Class CommandLine.ParseResult
- Enclosing class:
CommandLine
- Since:
- 3.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builds immutableParseResult
instances.static class
A group's multiplicity specifies how many matches of a group may appear on the command line.static class
Provides information about anCommandLine.ArgGroup
that was matched on the command line.(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CommandLine.Model.CommandSpec
private final CommandLine.ParseResult.GroupMatchContainer
private final List
<CommandLine.Model.ArgSpec> private final List
<CommandLine.Model.OptionSpec> private final List
<List<CommandLine.Model.PositionalParamSpec>> private final List
<CommandLine.Model.PositionalParamSpec> private final Set
<CommandLine.Model.OptionSpec> private final Set
<CommandLine.Model.PositionalParamSpec> private final List
<CommandLine.ParseResult> private final boolean
private final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns thisParseResult
as a list ofCommandLine
objects, one for each matched command/subcommand.builder
(CommandLine.Model.CommandSpec commandSpec) Creates and returns a newParseResult.Builder
for the specified command spec.Returns theCommandSpec
for the matched command.errors()
IfCommandLine.Model.ParserSpec.collectErrors
istrue
, returns the list of exceptions that were encountered during parsing, otherwise, returns an empty list.Returns the command line arguments after @-files were expanded; these are the arguments that were actually parsed.Returns the matches for the specified argument group.Returns the top-level container for theArgGroupSpec
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
(String name) Returns whether an option whose aliases include the specified name was matched on the command line.boolean
Returns whether the specified option was matched on the command line.boolean
hasMatchedPositional
(int position) Returns whether a positional parameter was matched at the specified position.boolean
Returns whether the specified positional parameter was matched on the command line.boolean
Returnstrue
if a subcommand was matched on the command line,false
otherwise.boolean
Returnstrue
if one of the options that was matched on the command line is ausageHelp
option.boolean
Returnstrue
if one of the options that was matched on the command line is aversionHelp
option.Returns a list of matched options and positional parameters, in order they were matched on the command line.matchedOption
(char shortName) Returns the option with the specified short name, ornull
if no option with that name was matched on the command line.matchedOption
(String name) Returns the option with the specified name, ornull
if no option with that name was matched on the command line.Returns a list of matched options, in order they were matched on the command line.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.private <T> T
matchedOptionValue
(CommandLine.Model.OptionSpec option, T defaultValue) Returns the command line argument value of the specified option, converted to the type of the option, or the specified default value if the specified option isnull
.matchedPositional
(int position) Returns the firstPositionalParamSpec
that matched an argument at the specified position, ornull
if no positional parameters were matched at that position.Returns a list of matched positional parameters, in order they were matched on the command line.matchedPositionals
(int position) Returns allPositionalParamSpec
objects that matched an argument at the specified position, or an empty list if no positional parameters were matched at that position.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.private <T> T
matchedPositionalValue
(CommandLine.Model.PositionalParamSpec positional, T defaultValue) Returns the command line argument value of the specified positional parameter, converted to the type of the positional parameter, or the specified default value if the specified positional parameter isnull
.Returns the original command line arguments that were passed to theCommandLine.parseArgs(String...)
method, before @-file expansion.private List
<CommandLine> recursivelyAddCommandLineTo
(List<CommandLine> result) Returns theParseResult
for the last subcommand of this command that was matched on the command line, ornull
if no subcommand was matched.Returns a list with theParseResult
objects for each subcommand of this command that was matched on the command line or an empty list if no subcommands were matched.Returns a list of command line arguments that did not match any options or positional parameters.(package private) void
-
Field Details
-
commandSpec
-
matchedUniqueOptions
-
matchedUniquePositionals
-
matchedArgs
-
matchedOptions
-
matchedPositionals
-
originalArgs
-
expandedArgs
-
unmatched
-
matchedPositionalParams
-
errors
-
groupMatchContainer
-
subcommands
-
tentativeMatch
-
usageHelpRequested
private final boolean usageHelpRequested -
versionHelpRequested
private final boolean versionHelpRequested
-
-
Constructor Details
-
ParseResult
-
-
Method Details
-
builder
Creates and returns a newParseResult.Builder
for the specified command spec. -
findMatches
public List<CommandLine.ParseResult.GroupMatchContainer> findMatches(CommandLine.Model.ArgGroupSpec group) Returns the matches for the specified argument group.- Since:
- 4.0
-
getGroupMatches
Returns the top-level container for theArgGroupSpec
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 aParameterException
being thrown by theparse
method, unless the parser is configured to collect errors.- Since:
- 4.0
-
matchedOption
Returns the option with the specified short name, ornull
if no option with that name was matched on the command line.Use
getValue
on the returnedOptionSpec
to get the matched value (or values), converted to the type of the option. Alternatively, usestringValues
to get the matched String values after they were split into parts, ororiginalStringValues
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()
.- See Also:
-
matchedOption
Returns the option with the specified name, ornull
if no option with that name was matched on the command line.Use
getValue
on the returnedOptionSpec
to get the matched value (or values), converted to the type of the option. Alternatively, usestringValues
to get the matched String values after they were split into parts, ororiginalStringValues
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()
.- Parameters:
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.- See Also:
-
matchedPositional
Returns the firstPositionalParamSpec
that matched an argument at the specified position, ornull
if no positional parameters were matched at that position. -
matchedPositionals
Returns allPositionalParamSpec
objects that matched an argument at the specified position, or an empty list if no positional parameters were matched at that position. -
commandSpec
Returns theCommandSpec
for the matched command. -
hasMatchedOption
public boolean hasMatchedOption(char shortName) Returns whether an option whose aliases include the specified short name was matched on the command line.- Parameters:
shortName
- used to search the matched options. May be an alias of the option name that was actually specified on the command line.
-
hasMatchedOption
Returns whether an option whose aliases include the specified name was matched on the command line.- Parameters:
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.
-
hasMatchedOption
Returns whether the specified option was matched on the command line. -
hasMatchedPositional
public boolean hasMatchedPositional(int position) Returns whether a positional parameter was matched at the specified position. -
hasMatchedPositional
Returns whether the specified positional parameter was matched on the command line. -
matchedOptionsSet
Returns a set of matched options.- Since:
- 4.0
-
matchedOptions
Returns a list of matched options, in order they were matched on the command line. The returned list may contain the sameOptionSpec
multiple times, if the option was matched multiple times on the command line. -
matchedPositionalsSet
Returns a set of matched positional parameters.- Since:
- 4.0
-
matchedPositionals
Returns a list of matched positional parameters, in order they were matched on the command line. The returned list may contain the samePositionalParamSpec
multiple times, if the parameter was matched multiple times on the command line. -
matchedArgs
Returns a list of matched options and positional parameters, in order they were matched on the command line. The returned list may contain anOptionSpec
orPositionalParamSpec
multiple times, if the option or parameter was matched multiple times on the command line.- Since:
- 4.0
-
unmatched
Returns a list of command line arguments that did not match any options or positional parameters. -
originalArgs
Returns the original command line arguments that were passed to theCommandLine.parseArgs(String...)
method, before @-file expansion.- See Also:
-
expandedArgs
Returns the command line arguments after @-files were expanded; these are the arguments that were actually parsed.- Since:
- 4.4
- See Also:
-
errors
IfCommandLine.Model.ParserSpec.collectErrors
istrue
, returns the list of exceptions that were encountered during parsing, otherwise, returns an empty list.- Since:
- 3.2
-
matchedOptionValue
public <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. -
matchedOptionValue
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. -
matchedOptionValue
Returns the command line argument value of the specified option, converted to the type of the option, or the specified default value if the specified option isnull
. -
matchedPositionalValue
public <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. -
matchedPositionalValue
private <T> T matchedPositionalValue(CommandLine.Model.PositionalParamSpec positional, T defaultValue) Returns the command line argument value of the specified positional parameter, converted to the type of the positional parameter, or the specified default value if the specified positional parameter isnull
. -
hasSubcommand
public boolean hasSubcommand()Returnstrue
if a subcommand was matched on the command line,false
otherwise. -
subcommand
Returns theParseResult
for the last subcommand of this command that was matched on the command line, ornull
if no subcommand was matched. -
subcommands
Returns a list with theParseResult
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'ssubcommandsRepeatable
attribute istrue
.- Since:
- 4.2
-
isUsageHelpRequested
public boolean isUsageHelpRequested()Returnstrue
if one of the options that was matched on the command line is ausageHelp
option. -
isVersionHelpRequested
public boolean isVersionHelpRequested()Returnstrue
if one of the options that was matched on the command line is aversionHelp
option. -
asCommandLineList
Returns thisParseResult
as a list ofCommandLine
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.- Since:
- 3.0
-
recursivelyAddCommandLineTo
-
validateGroups
void validateGroups()
-