public class CmdLineParser extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CmdLineParser.IllegalOptionValueException
Thrown when an illegal or missing value is given by the user for an option that takes a value.
|
static class |
CmdLineParser.NotFlagException
Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one or more
requires a value.
|
static class |
CmdLineParser.Option
Representation of a command-line option.
|
static class |
CmdLineParser.OptionException
Base class for exceptions that may be thrown when options are parsed.
|
static class |
CmdLineParser.UnknownOptionException
Thrown when the parsed command-line contains an option that is not recognised.
|
static class |
CmdLineParser.UnknownSuboptionException
Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one is
unknown.
|
Constructor and Description |
---|
CmdLineParser() |
Modifier and Type | Method and Description |
---|---|
CmdLineParser.Option |
addBooleanOption(char shortForm,
String longForm)
Convenience method for adding a boolean option.
|
CmdLineParser.Option |
addBooleanOption(String longForm)
Convenience method for adding a boolean option.
|
CmdLineParser.Option |
addDoubleOption(char shortForm,
String longForm)
Convenience method for adding a double option.
|
CmdLineParser.Option |
addDoubleOption(String longForm)
Convenience method for adding a double option.
|
CmdLineParser.Option |
addIntegerOption(char shortForm,
String longForm)
Convenience method for adding an integer option.
|
CmdLineParser.Option |
addIntegerOption(String longForm)
Convenience method for adding an integer option.
|
CmdLineParser.Option |
addLongOption(char shortForm,
String longForm)
Convenience method for adding a long integer option.
|
CmdLineParser.Option |
addLongOption(String longForm)
Convenience method for adding a long integer option.
|
CmdLineParser.Option |
addOption(CmdLineParser.Option opt)
Add the specified Option to the list of accepted options.
|
CmdLineParser.Option |
addStringOption(char shortForm,
String longForm)
Convenience method for adding a string option.
|
CmdLineParser.Option |
addStringOption(String longForm)
Convenience method for adding a string option.
|
Object |
getOptionValue(CmdLineParser.Option o)
Equivalent to
getOptionValue(o, null) . |
Object |
getOptionValue(CmdLineParser.Option o,
Object def)
Gets the option value.
|
List<String> |
getOptionValues(CmdLineParser.Option option)
Gets the option values.
|
List<String> |
getRemainingArgs()
Gets the remaining args.
|
void |
parse(String[] argv)
Extract the options and non-option arguments from the given list of command-line arguments.
|
void |
parse(String[] argv,
Locale locale)
Extract the options and non-option arguments from the given list of command-line arguments.
|
public final CmdLineParser.Option addOption(CmdLineParser.Option opt)
opt
- the optpublic final CmdLineParser.Option addStringOption(char shortForm, String longForm)
shortForm
- the short formlongForm
- the long formpublic final CmdLineParser.Option addStringOption(String longForm)
longForm
- the long formpublic final CmdLineParser.Option addIntegerOption(char shortForm, String longForm)
shortForm
- the short formlongForm
- the long formpublic final CmdLineParser.Option addIntegerOption(String longForm)
longForm
- the long formpublic final CmdLineParser.Option addLongOption(char shortForm, String longForm)
shortForm
- the short formlongForm
- the long formpublic final CmdLineParser.Option addLongOption(String longForm)
longForm
- the long formpublic final CmdLineParser.Option addDoubleOption(char shortForm, String longForm)
shortForm
- the short formlongForm
- the long formpublic final CmdLineParser.Option addDoubleOption(String longForm)
longForm
- the long formpublic final CmdLineParser.Option addBooleanOption(char shortForm, String longForm)
shortForm
- the short formlongForm
- the long formpublic final CmdLineParser.Option addBooleanOption(String longForm)
longForm
- the long formpublic final Object getOptionValue(CmdLineParser.Option o)
getOptionValue(o, null)
.o
- the opublic final Object getOptionValue(CmdLineParser.Option o, Object def)
o
- the odef
- the defpublic final List<String> getOptionValues(CmdLineParser.Option option)
option
- the optionpublic final List<String> getRemainingArgs()
public final void parse(String[] argv) throws CmdLineParser.IllegalOptionValueException, CmdLineParser.UnknownOptionException
argv
- the argvCmdLineParser.IllegalOptionValueException
- the illegal option value exceptionCmdLineParser.UnknownOptionException
- the unknown option exceptionpublic final void parse(String[] argv, Locale locale) throws CmdLineParser.IllegalOptionValueException, CmdLineParser.UnknownOptionException
argv
- the argvlocale
- the localeCmdLineParser.IllegalOptionValueException
- the illegal option value exceptionCmdLineParser.UnknownOptionException
- the unknown option exceptionCopyright © 2009–2020 Jeremy Landis. All rights reserved.