@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.
|
void |
addName(java.lang.String name,
boolean isHidden)
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 all names, including hidden names, for this
subcommand.
|
java.util.List<java.lang.String> |
getNames(boolean includeHidden)
Retrieves a list of the non-hidden 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(@NotNull java.lang.String name, @NotNull java.lang.String description, @NotNull ArgumentParser parser, @NotNull 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.@NotNull public java.lang.String getPrimaryName()
@NotNull public java.util.List<java.lang.String> getNames()
@NotNull public java.util.List<java.lang.String> getNames(boolean includeHidden)
includeHidden
- Indicates whether to include hidden names in the
list that is returned.public boolean hasName(@NotNull 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(@NotNull 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 void addName(@NotNull java.lang.String name, boolean isHidden) 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.isHidden
- Indicates whether the provided name should be hidden. A
hidden name may be used to invoke this subcommand but
will not be displayed in usage information.ArgumentException
- If the provided name is already registered with
this subcommand, or with another subcommand
also registered with the global argument
parser.@NotNull public java.lang.String getDescription()
@NotNull public ArgumentParser getArgumentParser()
public boolean isPresent()
true
if this subcommand was provided in the set of
command-line arguments, or false
if not.@NotNull public java.util.LinkedHashMap<java.lang.String[],java.lang.String> getExampleUsages()
@NotNull public SubCommand getCleanCopy()
@NotNull public java.lang.String toString()
toString
in class java.lang.Object