Class CmdLineParser
java.lang.Object
jargs.gnu.CmdLineParser
Largely GNU-compatible command-line options parser. Has short (-v) and long-form (--verbose) option support, and also
allows options with associated values (-d 2, --debug 2, --debug=2). Option processing can be explicitly terminated by
the argument '--'.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when an illegal or missing value is given by the user for an option that takes a value.static classThrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one or more requires a value.static classRepresentation of a command-line option.static classBase class for exceptions that may be thrown when options are parsed.static classThrown when the parsed command-line contains an option that is not recognised.static classThrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one is unknown. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal CmdLineParser.OptionaddBooleanOption(char shortForm, String longForm) Convenience method for adding a boolean option.final CmdLineParser.OptionaddBooleanOption(String longForm) Convenience method for adding a boolean option.final CmdLineParser.OptionaddDoubleOption(char shortForm, String longForm) Convenience method for adding a double option.final CmdLineParser.OptionaddDoubleOption(String longForm) Convenience method for adding a double option.final CmdLineParser.OptionaddIntegerOption(char shortForm, String longForm) Convenience method for adding an integer option.final CmdLineParser.OptionaddIntegerOption(String longForm) Convenience method for adding an integer option.final CmdLineParser.OptionaddLongOption(char shortForm, String longForm) Convenience method for adding a long integer option.final CmdLineParser.OptionaddLongOption(String longForm) Convenience method for adding a long integer option.final CmdLineParser.OptionAdd the specified Option to the list of accepted options.final CmdLineParser.OptionaddStringOption(char shortForm, String longForm) Convenience method for adding a string option.final CmdLineParser.OptionaddStringOption(String longForm) Convenience method for adding a string option.final ObjectEquivalent togetOptionValue(o, null).final ObjectgetOptionValue(CmdLineParser.Option o, Object def) Gets the option value.getOptionValues(CmdLineParser.Option option) Gets the option values.Gets the remaining args.final voidExtract the options and non-option arguments from the given list of command-line arguments.final voidExtract the options and non-option arguments from the given list of command-line arguments.
-
Constructor Details
-
CmdLineParser
public CmdLineParser()
-
-
Method Details
-
addOption
Add the specified Option to the list of accepted options.- Parameters:
opt- the opt- Returns:
- the option
-
addStringOption
Convenience method for adding a string option.- Parameters:
shortForm- the short formlongForm- the long form- Returns:
- the new Option
-
addStringOption
Convenience method for adding a string option.- Parameters:
longForm- the long form- Returns:
- the new Option
-
addIntegerOption
Convenience method for adding an integer option.- Parameters:
shortForm- the short formlongForm- the long form- Returns:
- the new Option
-
addIntegerOption
Convenience method for adding an integer option.- Parameters:
longForm- the long form- Returns:
- the new Option
-
addLongOption
Convenience method for adding a long integer option.- Parameters:
shortForm- the short formlongForm- the long form- Returns:
- the new Option
-
addLongOption
Convenience method for adding a long integer option.- Parameters:
longForm- the long form- Returns:
- the new Option
-
addDoubleOption
Convenience method for adding a double option.- Parameters:
shortForm- the short formlongForm- the long form- Returns:
- the new Option
-
addDoubleOption
Convenience method for adding a double option.- Parameters:
longForm- the long form- Returns:
- the new Option
-
addBooleanOption
Convenience method for adding a boolean option.- Parameters:
shortForm- the short formlongForm- the long form- Returns:
- the new Option
-
addBooleanOption
Convenience method for adding a boolean option.- Parameters:
longForm- the long form- Returns:
- the new Option
-
getOptionValue
Equivalent togetOptionValue(o, null).- Parameters:
o- the o- Returns:
- the option value
-
getOptionValue
Gets the option value.- Parameters:
o- the odef- the def- Returns:
- the parsed value of the given Option, or the given default 'def' if the option was not set
-
getOptionValues
Gets the option values.- Parameters:
option- the option- Returns:
- A Vector giving the parsed values of all the occurrences of the given Option, or an empty Vector if the option was not set.
-
getRemainingArgs
-
parse
public final void parse(String[] argv) throws CmdLineParser.IllegalOptionValueException, CmdLineParser.UnknownOptionException Extract the options and non-option arguments from the given list of command-line arguments. The default locale is used for parsing options whose values might be locale-specific.- Parameters:
argv- the argv- Throws:
CmdLineParser.IllegalOptionValueException- the illegal option value exceptionCmdLineParser.UnknownOptionException- the unknown option exception
-
parse
public final void parse(String[] argv, Locale locale) throws CmdLineParser.IllegalOptionValueException, CmdLineParser.UnknownOptionException Extract the options and non-option arguments from the given list of command-line arguments. The specified locale is used for parsing options whose values might be locale-specific.- Parameters:
argv- the argvlocale- the locale- Throws:
CmdLineParser.IllegalOptionValueException- the illegal option value exceptionCmdLineParser.UnknownOptionException- the unknown option exception
-