Class CommandLine.ParseResult
- java.lang.Object
-
- picocli.CommandLine.ParseResult
-
- Enclosing class:
- CommandLine
public static class CommandLine.ParseResult extends Object
Encapsulates the result of parsing an array of command line arguments.- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommandLine.ParseResult.BuilderBuilds immutableParseResultinstances.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<CommandLine>asCommandLineList()Returns thisParseResultas a list ofCommandLineobjects, one for each matched command/subcommand.static CommandLine.ParseResult.Builderbuilder(CommandLine.Model.CommandSpec commandSpec)Creates and returns a newParseResult.Builderfor the specified command spec.CommandLine.Model.CommandSpeccommandSpec()Returns theCommandSpecfor the matched command.List<Exception>errors()IfCommandLine.Model.ParserSpec.collectErrorsistrue, returns the list of exceptions that were encountered during parsing, otherwise, returns an empty list.booleanhasMatchedOption(char shortName)Returns whether an option whose aliases include the specified short name was matched on the command line.booleanhasMatchedOption(String name)Returns whether an option whose aliases include the specified name was matched on the command line.booleanhasMatchedOption(CommandLine.Model.OptionSpec option)Returns whether the specified option was matched on the command line.booleanhasMatchedPositional(int position)Returns whether a positional parameter was matched at the specified position.booleanhasMatchedPositional(CommandLine.Model.PositionalParamSpec positional)Returns whether the specified positional parameter was matched on the command line.booleanhasSubcommand()Returnstrueif a subcommand was matched on the command line,falseotherwise.booleanisUsageHelpRequested()Returnstrueif one of the options that was matched on the command line is ausageHelpoption.booleanisVersionHelpRequested()Returnstrueif one of the options that was matched on the command line is aversionHelpoption.CommandLine.Model.OptionSpecmatchedOption(char shortName)Returns the option with the specified short name, ornullif no option with that name was matched on the command line.CommandLine.Model.OptionSpecmatchedOption(String name)Returns the option with the specified name, ornullif no option with that name was matched on the command line.List<CommandLine.Model.OptionSpec>matchedOptions()Returns a list of matched options, in the order they were found on the command line.<T> TmatchedOptionValue(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> TmatchedOptionValue(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.PositionalParamSpecmatchedPositional(int position)Returns the firstPositionalParamSpecthat matched an argument at the specified position, ornullif no positional parameters were matched at that position.List<CommandLine.Model.PositionalParamSpec>matchedPositionals()Returns a list of matched positional parameters.List<CommandLine.Model.PositionalParamSpec>matchedPositionals(int position)Returns allPositionalParamSpecobjects that matched an argument at the specified position, or an empty list if no positional parameters were matched at that position.<T> TmatchedPositionalValue(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 command line arguments that were parsed.CommandLine.ParseResultsubcommand()Returns theParseResultfor the subcommand of this command that was matched on the command line, ornullif no subcommand was matched.List<String>unmatched()Returns a list of command line arguments that did not match any options or positional parameters.
-
-
-
Method Detail
-
builder
public static CommandLine.ParseResult.Builder builder(CommandLine.Model.CommandSpec commandSpec)
Creates and returns a newParseResult.Builderfor the specified command spec.
-
matchedOption
public CommandLine.Model.OptionSpec matchedOption(char shortName)
Returns the option with the specified short name, ornullif no option with that name was matched on the command line.Use
getValueon the returnedOptionSpecto get the matched value (or values), converted to the type of the option. Alternatively, usestringValuesto get the matched String values after they were split into parts, ororiginalStringValuesto 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 notmatched on the command line, use
parseResult.commandSpec().findOption(shortName).getValue().
-
matchedOption
public CommandLine.Model.OptionSpec matchedOption(String name)
Returns the option with the specified name, ornullif no option with that name was matched on the command line.Use
getValueon the returnedOptionSpecto get the matched value (or values), converted to the type of the option. Alternatively, usestringValuesto get the matched String values after they were split into parts, ororiginalStringValuesto 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 notmatched 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:
CommandLine.Model.CommandSpec.findOption(String)
-
matchedPositional
public CommandLine.Model.PositionalParamSpec matchedPositional(int position)
Returns the firstPositionalParamSpecthat matched an argument at the specified position, ornullif no positional parameters were matched at that position.
-
matchedPositionals
public List<CommandLine.Model.PositionalParamSpec> matchedPositionals(int position)
Returns allPositionalParamSpecobjects that matched an argument at the specified position, or an empty list if no positional parameters were matched at that position.
-
commandSpec
public CommandLine.Model.CommandSpec commandSpec()
Returns theCommandSpecfor 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
public boolean hasMatchedOption(String name)
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
public boolean hasMatchedOption(CommandLine.Model.OptionSpec option)
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
public boolean hasMatchedPositional(CommandLine.Model.PositionalParamSpec positional)
Returns whether the specified positional parameter was matched on the command line.
-
matchedOptions
public List<CommandLine.Model.OptionSpec> matchedOptions()
Returns a list of matched options, in the order they were found on the command line.
-
matchedPositionals
public List<CommandLine.Model.PositionalParamSpec> matchedPositionals()
Returns a list of matched positional parameters.
-
unmatched
public List<String> unmatched()
Returns a list of command line arguments that did not match any options or positional parameters.
-
originalArgs
public List<String> originalArgs()
Returns the command line arguments that were parsed.
-
errors
public List<Exception> errors()
IfCommandLine.Model.ParserSpec.collectErrorsistrue, 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
public <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.
-
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.
-
hasSubcommand
public boolean hasSubcommand()
Returnstrueif a subcommand was matched on the command line,falseotherwise.
-
subcommand
public CommandLine.ParseResult subcommand()
Returns theParseResultfor the subcommand of this command that was matched on the command line, ornullif no subcommand was matched.
-
isUsageHelpRequested
public boolean isUsageHelpRequested()
Returnstrueif one of the options that was matched on the command line is ausageHelpoption.
-
isVersionHelpRequested
public boolean isVersionHelpRequested()
Returnstrueif one of the options that was matched on the command line is aversionHelpoption.
-
asCommandLineList
public List<CommandLine> asCommandLineList()
Returns thisParseResultas a list ofCommandLineobjects, one for each matched command/subcommand. For backwards compatibility with pre-3.0 methods.
-
-