public static class CommandLine.ParseResult extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CommandLine.ParseResult.Builder
Builds immutable
ParseResult instances. |
static class |
CommandLine.ParseResult.GroupMatch
A group's multiplicity specifies how many matches of a group may
appear on the command line.
|
static class |
CommandLine.ParseResult.GroupMatchContainer
Provides information about an
CommandLine.ArgGroup that was matched on the command line. |
Modifier and Type | Method and Description |
---|---|
List<CommandLine> |
asCommandLineList()
Returns this
ParseResult as a list of CommandLine objects, one for each matched command/subcommand. |
static CommandLine.ParseResult.Builder |
builder(CommandLine.Model.CommandSpec commandSpec)
Creates and returns a new
ParseResult.Builder for the specified command spec. |
CommandLine.Model.CommandSpec |
commandSpec()
Returns the
CommandSpec for the matched command. |
List<Exception> |
errors()
If
CommandLine.Model.ParserSpec.collectErrors is true , returns the list of exceptions that were encountered during parsing, otherwise, returns an empty list. |
List<String> |
expandedArgs()
Returns the command line arguments after @-files were expanded;
these are the arguments that were actually parsed.
|
List<CommandLine.ParseResult.GroupMatchContainer> |
findMatches(CommandLine.Model.ArgGroupSpec group)
Returns the matches for the specified argument group.
|
List<CommandLine.ParseResult.GroupMatch> |
getGroupMatches()
Returns the top-level container for the
ArgGroupSpec match or matches found. |
boolean |
hasMatchedOption(char shortName)
Returns whether an option whose aliases include the specified short name was matched on the command line.
|
boolean |
hasMatchedOption(CommandLine.Model.OptionSpec option)
Returns whether the specified option was matched on the command line.
|
boolean |
hasMatchedOption(String name)
Returns whether an option whose aliases include the specified name was matched on the command line.
|
boolean |
hasMatchedPositional(CommandLine.Model.PositionalParamSpec positional)
Returns whether the specified positional parameter was matched on the command line.
|
boolean |
hasMatchedPositional(int position)
Returns whether a positional parameter was matched at the specified position.
|
boolean |
hasSubcommand()
Returns
true if a subcommand was matched on the command line, false otherwise. |
boolean |
isUsageHelpRequested()
Returns
true if one of the options that was matched on the command line is a usageHelp option. |
boolean |
isVersionHelpRequested()
Returns
true if one of the options that was matched on the command line is a versionHelp option. |
List<CommandLine.Model.ArgSpec> |
matchedArgs()
Returns a list of matched options and positional parameters, in order they were matched on the command line.
|
CommandLine.Model.OptionSpec |
matchedOption(char shortName)
Returns the option with the specified short name, or
null if no option with that name was matched
on the command line. |
CommandLine.Model.OptionSpec |
matchedOption(String name)
Returns the option with the specified name, or
null if no option with that name was matched on the command line. |
List<CommandLine.Model.OptionSpec> |
matchedOptions()
Returns a list of matched options, in order they were matched on the command line.
|
Set<CommandLine.Model.OptionSpec> |
matchedOptionsSet()
Returns a set of matched options.
|
<T> T |
matchedOptionValue(char shortName,
T defaultValue)
Returns the command line argument value of the option with the specified name, converted to the type of the option, or the specified default value if no option with the specified name was matched.
|
<T> T |
matchedOptionValue(String name,
T defaultValue)
Returns the command line argument value of the option with the specified name, converted to the type of the option, or the specified default value if no option with the specified name was matched.
|
CommandLine.Model.PositionalParamSpec |
matchedPositional(int position)
Returns the first
PositionalParamSpec that matched an argument at the specified position, or null if no positional parameters were matched at that position. |
List<CommandLine.Model.PositionalParamSpec> |
matchedPositionals()
Returns a list of matched positional parameters, in order they were matched on the command line.
|
List<CommandLine.Model.PositionalParamSpec> |
matchedPositionals(int position)
Returns all
PositionalParamSpec objects that matched an argument at the specified position, or an empty list if no positional parameters were matched at that position. |
Set<CommandLine.Model.PositionalParamSpec> |
matchedPositionalsSet()
Returns a set of matched positional parameters.
|
<T> T |
matchedPositionalValue(int position,
T defaultValue)
Returns the command line argument value of the positional parameter at the specified position, converted to the type of the positional parameter, or the specified default value if no positional parameter was matched at that position.
|
List<String> |
originalArgs()
Returns the original command line arguments that were passed to the
CommandLine.parseArgs(String...) method, before @-file expansion. |
CommandLine.ParseResult |
subcommand()
Returns the
ParseResult for the last subcommand of this command that was matched on the command line, or null if no subcommand was matched. |
List<CommandLine.ParseResult> |
subcommands()
Returns a list with the
ParseResult objects for each subcommand of this command
that was matched on the command line or an empty list if no subcommands were matched. |
List<String> |
unmatched()
Returns a list of command line arguments that did not match any options or positional parameters.
|
public static CommandLine.ParseResult.Builder builder(CommandLine.Model.CommandSpec commandSpec)
ParseResult.Builder
for the specified command spec.public List<CommandLine.ParseResult.GroupMatchContainer> findMatches(CommandLine.Model.ArgGroupSpec group)
public List<CommandLine.ParseResult.GroupMatch> getGroupMatches()
ArgGroupSpec
match or matches found.
If the user input was a valid combination of group arguments, the returned list should contain a single
match. Details of the matched groups encountered
on the command line can be obtained via its matchedSubgroups()
method.
The top-level match returned by this method contains no matched arguments.
If the returned list contains more than one match, the user input was invalid:
the maximum multiplicity of a group was exceeded, and the parser created an extra
match
to capture the values. Usually this results in a ParameterException
being thrown by the parse
method, unless the parser is configured to collect errors.
public CommandLine.Model.OptionSpec matchedOption(char shortName)
null
if no option with that name was matched
on the command line.
Use getValue
on the returned OptionSpec
to get the matched value (or values),
converted to the type of the option. Alternatively, use stringValues
to get the matched String values after they were split into parts, or
originalStringValues
to get the original String values that were
matched on the command line, before any processing.
To get the default value of an option that was
not matched on the command line, use
parseResult.commandSpec().findOption(shortName).getValue()
.
public CommandLine.Model.OptionSpec matchedOption(String name)
null
if no option with that name was matched on the command line.
Use getValue
on the returned OptionSpec
to get the matched value (or values),
converted to the type of the option. Alternatively, use stringValues
to get the matched String values after they were split into parts, or
originalStringValues
to get the original String values that were
matched on the command line, before any processing.
To get the default value of an option that was
not matched on the command line, use
parseResult.commandSpec().findOption(String).getValue()
.
name
- used to search the matched options. May be an alias of the option name that was actually specified on the command line.
The specified name may include option name prefix characters or not.CommandLine.Model.CommandSpec.findOption(String)
public CommandLine.Model.PositionalParamSpec matchedPositional(int position)
PositionalParamSpec
that matched an argument at the specified position, or null
if no positional parameters were matched at that position.public List<CommandLine.Model.PositionalParamSpec> matchedPositionals(int position)
PositionalParamSpec
objects that matched an argument at the specified position, or an empty list if no positional parameters were matched at that position.public CommandLine.Model.CommandSpec commandSpec()
CommandSpec
for the matched command.public boolean hasMatchedOption(char shortName)
shortName
- used to search the matched options. May be an alias of the option name that was actually specified on the command line.public boolean hasMatchedOption(String name)
name
- used to search the matched options. May be an alias of the option name that was actually specified on the command line.
The specified name may include option name prefix characters or not.public boolean hasMatchedOption(CommandLine.Model.OptionSpec option)
public boolean hasMatchedPositional(int position)
public boolean hasMatchedPositional(CommandLine.Model.PositionalParamSpec positional)
public Set<CommandLine.Model.OptionSpec> matchedOptionsSet()
public List<CommandLine.Model.OptionSpec> matchedOptions()
OptionSpec
multiple times, if the option was matched multiple times on the command line.public Set<CommandLine.Model.PositionalParamSpec> matchedPositionalsSet()
public List<CommandLine.Model.PositionalParamSpec> matchedPositionals()
PositionalParamSpec
multiple times, if the parameter was matched multiple times on the command line.public List<CommandLine.Model.ArgSpec> matchedArgs()
OptionSpec
or PositionalParamSpec
multiple times, if the option or parameter was matched multiple times on the command line.public List<String> unmatched()
public List<String> originalArgs()
CommandLine.parseArgs(String...)
method, before @-file expansion.expandedArgs()
public List<String> expandedArgs()
originalArgs()
public List<Exception> errors()
CommandLine.Model.ParserSpec.collectErrors
is true
, returns the list of exceptions that were encountered during parsing, otherwise, returns an empty list.public <T> T matchedOptionValue(char shortName, T defaultValue)
public <T> T matchedOptionValue(String name, T defaultValue)
public <T> T matchedPositionalValue(int position, T defaultValue)
public boolean hasSubcommand()
true
if a subcommand was matched on the command line, false
otherwise.public CommandLine.ParseResult subcommand()
ParseResult
for the last subcommand of this command that was matched on the command line, or null
if no subcommand was matched.public List<CommandLine.ParseResult> subcommands()
ParseResult
objects for each subcommand of this command
that was matched on the command line or an empty list if no subcommands were matched.
The returned list can only contain multiple values if this command's subcommandsRepeatable
attribute is true
.public boolean isUsageHelpRequested()
true
if one of the options that was matched on the command line is a usageHelp
option.public boolean isVersionHelpRequested()
true
if one of the options that was matched on the command line is a versionHelp
option.public List<CommandLine> asCommandLineList()
ParseResult
as a list of CommandLine
objects, one for each matched command/subcommand.
Note that for repeatable subcommands, there may be multiple commands at each level of the hierarchy in the returned list.