public final class CLAParser extends Object
-v) and GNU-style
long-form (e.g. --verbose) options (short-form is mandatory,
long-form optional).
Option processing can be explicitly terminated by the argument
"--", to allow (non-option) arguments to be specified.
All options must have at least a short name, and may also have a long name
(recommended).
An option that requires no value is considered a boolean/flag.
Options that require values have the value specified immediately after the
option name on the command-line.
For example, an option to display a help message might be specified
with the short name ? and the long name help
(abbreviated to [-?,--help] in the usage message).
An option for a size value might be specified as [-s,--size]
and require a value parameter, which may be specified in any of these forms:
-s 123-s=123-s:123/s 123/s=123/s:123--size 123--size=123--size:123Combining these the command-line may look like these examples, depending how the application has been configured:
java AppName [-?,--help] [--size <integer>]
java AppName -w,--width <integer> -h,--height <integer> [-?]
where options in [brackets] are optional, and others are mandatory.
Here are some of the features of JCLAP:
OptionException type for signalling parsing/retrieval problems.
Automatic usage printing can be accessed via the printUsage(...)
method, allowing printing to a specified PrintStream in either long
or short versions.
The options are printed in the same order in which they were added to the
CLAParser instance. The command used to launch the application
can either be user-specified, or can be deduced automatically if required.
An additional usage suffix string can also be specified if required,
allowing use of non-option arguments.
Internationalization support is included for a few locales (en/fr/de/es/pt), and may be extended in future. If required users may author their own locale property files to reference.
For an example of how to use the CLAParser class, visit the website.
| Constructor and Description |
|---|
CLAParser()
Creates a new
CLAParser instance, using the default locale. |
| Modifier and Type | Method and Description |
|---|---|
Option<Boolean> |
addBooleanOption(String shortName)
Convenience method to add an
Option of type Boolean
(single value allowed). |
Option<Boolean> |
addBooleanOption(String shortName,
boolean allowMany)
Convenience method to add an
Option of type Boolean. |
Option<Boolean> |
addBooleanOption(String shortName,
int maxCount)
Convenience method to add an
Option of type Boolean. |
Option<Boolean> |
addBooleanOption(String shortName,
String longName,
String description)
Convenience method to add an
Option of type Boolean
(single value allowed). |
Option<Boolean> |
addBooleanOption(String shortName,
String longName,
String description,
boolean allowMany)
Convenience method to add an
Option of type Boolean. |
Option<Boolean> |
addBooleanOption(String shortName,
String longName,
String description,
int maxCount)
Convenience method to add an
Option of type Boolean. |
Option<Boolean> |
addBooleanOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type Boolean. |
Option<Double> |
addDoubleOption(String shortName,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Double. |
Option<Double> |
addDoubleOption(String shortName,
int minCount,
int maxCount)
Convenience method to add an
Option of type Double. |
Option<Double> |
addDoubleOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Double. |
Option<Double> |
addDoubleOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type Double. |
Option<Integer> |
addEnumIntegerOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany,
int[] allowedValues)
Convenience method to add an
Option of enumerated Integer type. |
Option<Integer> |
addEnumIntegerOption(String shortName,
String longName,
String description,
int[] allowedValues)
Convenience method to add an
Option of enumerated Integer type
(single value allowed, non-mandatory). |
Option<String> |
addEnumStringOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany,
String[] allowedValues)
Convenience method to add an
Option of enumerated String type
(case-insensitive string matching). |
Option<String> |
addEnumStringOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany,
String[] allowedValues,
boolean ignoreCase)
Convenience method to add an
Option of enumerated String type. |
Option<String> |
addEnumStringOption(String shortName,
String longName,
String description,
int minCount,
int maxCount,
String[] allowedValues,
boolean ignoreCase)
Convenience method to add an
Option of enumerated String type. |
Option<String> |
addEnumStringOption(String shortName,
String longName,
String description,
String[] allowedValues)
Convenience method to add an
Option of enumerated String type
(single value allowed, non-mandatory). |
Option<String> |
addFileExistingOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type String which
refers to an existing file (which is not a folder). |
Option<String> |
addFileExistingOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type String which
refers to an existing file (which is not a folder). |
Option<String> |
addFileNewOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type String which
refers to a new or existing file/folder. |
Option<String> |
addFileOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type String which
refers to a file/folder. |
Option<Float> |
addFloatOption(String shortName,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Float. |
Option<Float> |
addFloatOption(String shortName,
int minCount,
int maxCount)
Convenience method to add an
Option of type Float. |
Option<Float> |
addFloatOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Float. |
Option<Float> |
addFloatOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type Float. |
Option<String> |
addFolderExistingOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type String which
refers to an existing folder. |
Option<String> |
addFolderExistingOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type String which
refers to an existing folder. |
Option<Integer> |
addIntegerOption(String shortName,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Integer. |
Option<Integer> |
addIntegerOption(String shortName,
int minCount,
int maxCount)
Convenience method to add an
Option of type Integer. |
Option<Integer> |
addIntegerOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Integer. |
Option<Integer> |
addIntegerOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type Integer. |
Option<LocalDate> |
addLocalDateOption(String shortName,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type LocalDate
(no long name, no description). |
Option<LocalDate> |
addLocalDateOption(String shortName,
int minCount,
int maxCount)
Convenience method to add an
Option of type LocalDate
(no long name, no description). |
Option<LocalDate> |
addLocalDateOption(String shortName,
String longName,
String description)
Convenience method to add an
Option of type LocalDate
(single value allowed, non-mandatory). |
Option<LocalDate> |
addLocalDateOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type LocalDate. |
Option<LocalDate> |
addLocalDateOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type LocalDate. |
Option<Long> |
addLongOption(String shortName,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Long. |
Option<Long> |
addLongOption(String shortName,
int minCount,
int maxCount)
Convenience method to add an
Option of type Long. |
Option<Long> |
addLongOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type Long. |
Option<Long> |
addLongOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type Long. |
<T> Option<T> |
addOption(Option<T> opt)
Adds the specified
Option to the list of those to be parsed
from the command-line arguments. |
Option<String> |
addStringOption(String shortName,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type String
(no long name, no description). |
Option<String> |
addStringOption(String shortName,
int minCount,
int maxCount)
Convenience method to add an
Option of type String
(no long name, no description). |
Option<String> |
addStringOption(String shortName,
String longName,
String description)
Convenience method to add an
Option of type String
(single value allowed, non-mandatory). |
Option<String> |
addStringOption(String shortName,
String longName,
String description,
boolean mandatory,
boolean allowMany)
Convenience method to add an
Option of type String. |
Option<String> |
addStringOption(String shortName,
String longName,
String description,
int minCount,
int maxCount)
Convenience method to add an
Option of type String. |
Boolean |
getBooleanOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or
false if the option was not set. |
Boolean |
getBooleanOptionValue(String optionName,
Boolean def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<Boolean> |
getBooleanOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
Double |
getDoubleOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or null if the option was not set.
|
Double |
getDoubleOptionValue(String optionName,
Double def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<Double> |
getDoubleOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
File |
getFileOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or null if the option was not set.
|
File |
getFileOptionValue(String optionName,
File def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<File> |
getFileOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
Float |
getFloatOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or null if the option was not set.
|
Float |
getFloatOptionValue(String optionName,
Float def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<Float> |
getFloatOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
Integer |
getIntegerOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or null if the option was not set.
|
Integer |
getIntegerOptionValue(String optionName,
Integer def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<Integer> |
getIntegerOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
LocalDate |
getLocalDateOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or null if the option was not set.
|
LocalDate |
getLocalDateOptionValue(String optionName,
LocalDate def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<LocalDate> |
getLocalDateOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
Long |
getLongOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or null if the option was not set.
|
Long |
getLongOptionValue(String optionName,
Long def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<Long> |
getLongOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
List<String> |
getNonOptionArguments()
Returns a list of the non-option command-line arguments.
|
<T> Option<T> |
getOption(String optionName,
Class<T> type)
Returns the
Option with the specified name (either short or long). |
List<Option> |
getOptions()
Returns all the
Option instances registered with the parser. |
<T> T |
getOptionValue(Option<T> opt)
Convenience method to return the parsed value of the specified option,
or null if the option was not set.
|
<T> T |
getOptionValue(Option<T> opt,
T def)
Convenience method to return the parsed value of the specified option,
or the specified default value if the option was not set.
|
<T> T |
getOptionValue(String optionName,
Class<T> type)
Convenience method to return the parsed value of the named option,
or null if the option was not set,
equivalent to
getOptionValue(optionName, type, null). |
<T> T |
getOptionValue(String optionName,
Class<T> type,
T def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
<T> List<T> |
getOptionValues(Option<T> opt)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
<T> List<T> |
getOptionValues(String optionName,
Class<T> type)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
String |
getStringOptionValue(String optionName)
Convenience method to return the parsed value of the named option,
or null if the option was not set.
|
String |
getStringOptionValue(String optionName,
String def)
Convenience method to return the parsed value of the named option,
or the specified default value if the option was not set.
|
List<String> |
getStringOptionValues(String optionName)
Returns a list of all the parsed values for the specified option,
or an empty list if the option was not set.
|
void |
parse(String[] args)
Extract the option-mapped and unmapped arguments from the given array of
command-line arguments, using the specified locale.
|
boolean |
parsedSolitaryHyphen()
Returns whether a single
- argument was found. |
void |
parseOrig(String[] args)
Extract the option-mapped and unmapped arguments from the given array of
command-line arguments, using the specified locale.
|
void |
printUsage(PrintStream ps,
boolean longUsage)
Prints the command-line usage message to the specified
PrintStream,
making a guess at the application launch command. |
void |
printUsage(PrintStream ps,
boolean longUsage,
String suffixArgs)
Prints the command-line usage message to the specified
PrintStream. |
void |
printUsage(PrintStream ps,
boolean longUsage,
String appString,
String suffixArgs)
Prints the command-line usage message to the specified
PrintStream. |
void |
setHidden(String optionName)
Hides the specified
Option from being printed in the usage message. |
public CLAParser()
CLAParser instance, using the default locale.public boolean parsedSolitaryHyphen()
- argument was found.
This is typically used to specify that an application should read from
STDIN or write to STDOUT. The argument is written to the non-option
arguments, so this can be tested independently, but this is just a
convenience method to do the same.public <T> Option<T> addOption(Option<T> opt)
Option to the list of those to be parsed
from the command-line arguments.T - the return type of the optionopt - Option instance to addOption instance that was addedIllegalArgumentException - if either short/long name of the specified
Option is already in usepublic void setHidden(String optionName) throws OptionException
Option from being printed in the usage message.optionName - short/long name of option to "hide"OptionException - if the specified option can't be foundpublic Option<Boolean> addBooleanOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type Boolean.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Boolean> addBooleanOption(String shortName, String longName, String description, boolean allowMany)
Option of type Boolean.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)allowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Boolean> addBooleanOption(String shortName, String longName, String description, int maxCount)
Option of type Boolean.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)maxCount - maximum number of occurrences required for this optionOption instancepublic Option<Boolean> addBooleanOption(String shortName, String longName, String description)
Option of type Boolean
(single value allowed).shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)Option instancepublic Option<Boolean> addBooleanOption(String shortName, boolean allowMany)
Option of type Boolean.shortName - short name of the optionallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Boolean> addBooleanOption(String shortName, int maxCount)
Option of type Boolean.shortName - short name of the optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Boolean> addBooleanOption(String shortName)
Option of type Boolean
(single value allowed).shortName - short name of the optionOption instancepublic Option<Integer> addIntegerOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type Integer.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Integer> addIntegerOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type Integer.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Integer> addIntegerOption(String shortName, boolean mandatory, boolean allowMany)
Option of type Integer.shortName - short name of the optionmandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Integer> addIntegerOption(String shortName, int minCount, int maxCount)
Option of type Integer.shortName - short name of the optionminCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Long> addLongOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type Long.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Long> addLongOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type Long.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Long> addLongOption(String shortName, boolean mandatory, boolean allowMany)
Option of type Long.shortName - short name of the optionmandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Long> addLongOption(String shortName, int minCount, int maxCount)
Option of type Long.shortName - short name of the optionminCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Double> addDoubleOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type Double.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Double> addDoubleOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type Double.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Double> addDoubleOption(String shortName, boolean mandatory, boolean allowMany)
Option of type Double.shortName - short name of the optionmandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Double> addDoubleOption(String shortName, int minCount, int maxCount)
Option of type Double.shortName - short name of the optionminCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Float> addFloatOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type Float.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Float> addFloatOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type Float.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<Float> addFloatOption(String shortName, boolean mandatory, boolean allowMany)
Option of type Float.shortName - short name of the optionmandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<Float> addFloatOption(String shortName, int minCount, int maxCount)
Option of type Float.shortName - short name of the optionminCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<String> addStringOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type String.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<String> addStringOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type String.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<String> addStringOption(String shortName, String longName, String description)
Option of type String
(single value allowed, non-mandatory).shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)Option instancepublic Option<String> addStringOption(String shortName, boolean mandatory, boolean allowMany)
Option of type String
(no long name, no description).shortName - short name of the optionmandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<String> addStringOption(String shortName, int minCount, int maxCount)
Option of type String
(no long name, no description).shortName - short name of the optionminCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<String> addFileOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type String which
refers to a file/folder.
For example, use this method to:
shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<String> addFileNewOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type String which
refers to a new or existing file/folder.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<String> addFileExistingOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type String which
refers to an existing file (which is not a folder).
For example, use this method to:
shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<String> addFileExistingOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type String which
refers to an existing file (which is not a folder).
For example, use this method to:
shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<String> addFolderExistingOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type String which
refers to an existing folder.
For example, use this method to enforce specification of an existing folder.
To allow specification of a new folder (one that does not yet exist),
use the addFileOption() method instead.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<String> addFolderExistingOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type String which
refers to an existing folder.
For example, use this method to enforce specification of an existing folder.
To allow specification of a new folder (one that does not yet exist),
use the addFileOption() method instead.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<String> addEnumStringOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany, String[] allowedValues, boolean ignoreCase)
Option of enumerated String type.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)allowedValues - array of string values allowed by this enumerated optionignoreCase - whether to ignore the case of string valuesOption instancepublic Option<String> addEnumStringOption(String shortName, String longName, String description, int minCount, int maxCount, String[] allowedValues, boolean ignoreCase)
Option of enumerated String type.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionallowedValues - array of string values allowed by this enumerated optionignoreCase - whether to ignore the case of string valuesOption instancepublic Option<String> addEnumStringOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany, String[] allowedValues)
Option of enumerated String type
(case-insensitive string matching).shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)allowedValues - array of string values allowed by this enumerated optionOption instancepublic Option<String> addEnumStringOption(String shortName, String longName, String description, String[] allowedValues)
Option of enumerated String type
(single value allowed, non-mandatory).shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)allowedValues - array of string values allowed by this enumerated optionOption instancepublic Option<Integer> addEnumIntegerOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany, int[] allowedValues)
Option of enumerated Integer type.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)allowedValues - array of string values allowed by this enumerated optionOption instancepublic Option<Integer> addEnumIntegerOption(String shortName, String longName, String description, int[] allowedValues)
Option of enumerated Integer type
(single value allowed, non-mandatory).shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)allowedValues - array of string values allowed by this enumerated optionOption instancepublic Option<LocalDate> addLocalDateOption(String shortName, String longName, String description, boolean mandatory, boolean allowMany)
Option of type LocalDate.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)mandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<LocalDate> addLocalDateOption(String shortName, String longName, String description, int minCount, int maxCount)
Option of type LocalDate.shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)minCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic Option<LocalDate> addLocalDateOption(String shortName, String longName, String description)
Option of type LocalDate
(single value allowed, non-mandatory).shortName - short name of the optionlongName - long name of the optiondescription - helpful description of the option (printed for usage message)Option instancepublic Option<LocalDate> addLocalDateOption(String shortName, boolean mandatory, boolean allowMany)
Option of type LocalDate
(no long name, no description).shortName - short name of the optionmandatory - whether this option must be specifiedallowMany - whether this option can take more than one value (i.e. be specified more than once)Option instancepublic Option<LocalDate> addLocalDateOption(String shortName, int minCount, int maxCount)
Option of type LocalDate
(no long name, no description).shortName - short name of the optionminCount - minimum number of occurrences required for this optionmaxCount - maximum number of occurrences required for this optionOption instancepublic <T> Option<T> getOption(String optionName, Class<T> type) throws OptionException
Option with the specified name (either short or long).T - the return type of the optionoptionName - option name for which to get value (either short/long)type - class type for option value compatability checkOptionException - if optionName is null, cannot be found, or is of the wrong typepublic final List<Option> getOptions()
Option instances registered with the parser.public <T> List<T> getOptionValues(Option<T> opt) throws OptionException
T - the return type of the optionopt - option for which to get valuesOptionException - if opt is null, cannot be found, or is of the wrong typepublic <T> List<T> getOptionValues(String optionName, Class<T> type) throws OptionException
Option.T - the return type of the optionoptionName - option name for which to get value (either short/long)type - class type for option value compatability checkOptionException - if optionName is null, cannot be found, or is of the wrong typepublic <T> T getOptionValue(Option<T> opt) throws OptionException
T - the return type of the optionopt - option for which to get valueOptionException - if opt is null, cannot be found, or is of the wrong typepublic <T> T getOptionValue(Option<T> opt, T def) throws OptionException
T - the return type of the optionopt - option for which to get valuedef - default value to use if the option was not setOptionException - if opt is null, cannot be found, or is of the wrong typepublic <T> T getOptionValue(String optionName, Class<T> type, T def) throws OptionException
T - the return type of the optionoptionName - name of the optiontype - class type for option value compatability checkdef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic <T> T getOptionValue(String optionName, Class<T> type) throws OptionException
getOptionValue(optionName, type, null).
This method should only be used with typed options that cannot take
multiple values.T - the return type of the optionoptionName - name of the optiontype - class type for option value compatability checkOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<Boolean> getBooleanOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Boolean getBooleanOptionValue(String optionName, Boolean def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Boolean getBooleanOptionValue(String optionName) throws OptionException
false if the option was not set. This method
should only be used with options that cannot take multiple values.
NOTE: this method operates slightly differently compared to the other
getXOptionValue(String) methods, in that when the option is not
defined, it returned Boolean.FALSE instead of null.optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<Integer> getIntegerOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Integer getIntegerOptionValue(String optionName, Integer def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Integer getIntegerOptionValue(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<Long> getLongOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Long getLongOptionValue(String optionName, Long def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Long getLongOptionValue(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<Double> getDoubleOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Double getDoubleOptionValue(String optionName, Double def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Double getDoubleOptionValue(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<Float> getFloatOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Float getFloatOptionValue(String optionName, Float def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic Float getFloatOptionValue(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<String> getStringOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic String getStringOptionValue(String optionName, String def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic String getStringOptionValue(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<LocalDate> getLocalDateOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic LocalDate getLocalDateOptionValue(String optionName, LocalDate def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic LocalDate getLocalDateOptionValue(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<File> getFileOptionValues(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic File getFileOptionValue(String optionName, File def) throws OptionException
optionName - name of the optiondef - default value to use if the option was not setOptionException - if optionName is null, cannot be found, or is of the wrong typepublic File getFileOptionValue(String optionName) throws OptionException
optionName - name of the optionOptionException - if optionName is null, cannot be found, or is of the wrong typepublic List<String> getNonOptionArguments()
For example:
java DemoApp -i 10 -f 1.2 foo -s bar fu bar
for an application with value-taking options i/f/s,
would return [foo,fu,bar] from this method.
public void parseOrig(String[] args) throws OptionException
args - command-line arguments (as passed into main method)OptionException - if an problem is encountered parsing the specified argumentspublic void parse(String[] args) throws OptionException
args - command-line arguments (as passed into main method)OptionException - if an problem is encountered parsing the specified argumentspublic void printUsage(PrintStream ps, boolean longUsage)
PrintStream,
making a guess at the application launch command.
The usage message is automatically created using the options specified.
The usage can be displayed in either short or long versions, although the
long version uses the options' description fields, which are not required,
but should generally be included if intending to print the long usage.ps - PrintStream to which to print usage messagelongUsage - whether to print long version of usage message (otherwise print short version)public void printUsage(PrintStream ps, boolean longUsage, String suffixArgs)
PrintStream.
The usage message is automatically created using the options specified.
The usage can be displayed in either short or long versions, although the
long version uses the options' description fields, which are not required,
but should generally be included if intending to print the long usage.ps - PrintStream to which to print usage messagelongUsage - whether to print long version of usage message (otherwise print short version)suffixArgs - usage suffix string for defining extra argumentspublic void printUsage(PrintStream ps, boolean longUsage, String appString, String suffixArgs)
PrintStream.
The usage message is automatically created using the options specified.
The usage can be displayed in either short or long versions, although the
long version uses the options' description fields, which are not required,
but should generally be included if intending to print the long usage.ps - PrintStream to which to print usage messagelongUsage - whether to print long version of usage message (otherwise print short version)appString - usage prefix string describing how application is launched; null specifies to create value automatically (e.g. "java foo.bar.AppName")suffixArgs - usage suffix string for defining extra argumentsCopyright © 2015. All rights reserved.