@Mutable @ThreadSafety(level=INTERFACE_NOT_THREADSAFE) public final class SubCommand extends java.lang.Object
Constructor and Description |
---|
SubCommand(java.lang.String name,
java.lang.String description,
ArgumentParser parser,
java.util.LinkedHashMap<java.lang.String[],java.lang.String> exampleUsages)
Creates a new subcommand with the provided information.
|
Modifier and Type | Method and Description |
---|---|
void |
addName(java.lang.String name)
Adds the provided name that may be used to reference this subcommand.
|
ArgumentParser |
getArgumentParser()
Retrieves the argument parser that will be used to process arguments
specific to this subcommand.
|
SubCommand |
getCleanCopy()
Creates a copy of this subcommand that is "clean" and appears as if it has
not been used to parse an argument set.
|
java.lang.String |
getDescription()
Retrieves the description for this subcommand.
|
java.util.LinkedHashMap<java.lang.String[],java.lang.String> |
getExampleUsages()
Retrieves a set of information that may be used to generate example usage
information when the tool is run with this subcommand.
|
java.util.List<java.lang.String> |
getNames()
Retrieves the list of names for this subcommand.
|
java.lang.String |
getPrimaryName()
Retrieves the primary name for this subcommand, which is the first name
that was assigned to it.
|
boolean |
hasName(java.lang.String name)
Indicates whether the provided name is assigned to this subcommand.
|
boolean |
isPresent()
Indicates whether this subcommand was provided in the set of command-line
arguments.
|
java.lang.String |
toString()
Retrieves a string representation of this subcommand.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this subcommand to the provided buffer.
|
public SubCommand(java.lang.String name, java.lang.String description, ArgumentParser parser, java.util.LinkedHashMap<java.lang.String[],java.lang.String> exampleUsages) throws ArgumentException
name
- A name that may be used to reference this subcommand
in the argument list. It must not be null
or empty, and it will be treated in a
case-insensitive manner.description
- The description for this subcommand. It must not be
null
.parser
- The argument parser that will be used to validate
the subcommand-specific arguments. It must not be
null
, it must not be configured with any
subcommands of its own, and it must not be
configured to allow unnamed trailing arguments.exampleUsages
- An optional map correlating a complete set of
arguments that may be used when running the tool
with this subcommand (including the subcommand and
any appropriate global and/or subcommand-specific
arguments) and a description of the behavior with
that subcommand.ArgumentException
- If there is a problem with the provided name,
description, or argument parser.public java.lang.String getPrimaryName()
public java.util.List<java.lang.String> getNames()
public boolean hasName(java.lang.String name)
name
- The name for which to make the determination. It must not be
null
.true
if the provided name is assigned to this subcommand,
or false
if not.public void addName(java.lang.String name) throws ArgumentException
name
- A name that may be used to reference this subcommand in the
argument list. It must not be null
or empty, and it
will be treated in a case-insensitive manner.ArgumentException
- If the provided name is already registered with
this subcommand, or with another subcommand
also registered with the global argument
parser.public java.lang.String getDescription()
public ArgumentParser getArgumentParser()
public boolean isPresent()
true
if this subcommand was provided in the set of
command-line arguments, or false
if not.public java.util.LinkedHashMap<java.lang.String[],java.lang.String> getExampleUsages()
public SubCommand getCleanCopy()
public java.lang.String toString()
toString
in class java.lang.Object
public void toString(java.lang.StringBuilder buffer)
buffer
- The buffer to which the information should be appended.