|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sadun.util.CmdLineOptions
A class to handle command line options.
Client code either uses the setObjectOnOption()
and/or setOnOption methods; or subclasses
CmdLineOptions.Handler
by implementing a method with
signature
public void option(String option, CmdLineOptions.Handler.ParamSet ps, boolean value);with callback code for each option and registers the subclasses with an instance of this class.
Invoking the parse()
method examines the command line
and executes the callback code.
An option may be given a priority (the default priority is 0). When parsing arguments with parse(String[], String)
,
options with higher priorities will be handled first.
Other features are the possibility of definining option aliases, option descriptions an automatic usage printout build up over this information.
Nested Class Summary | |
static class |
CmdLineOptions.ChainedHandler
A chained handler: executes two handlers one after the other. |
static interface |
CmdLineOptions.DefaultsStreamParser
Objects implementing this interface translate an input stream into a map of default values per options for the CmdLineOptions#useDefaultStream(InputStream, DefaultsStreamParser) method of CmdLineOptions .
|
static class |
CmdLineOptions.Handler
This class handles an option and can be subclassed to define the reaction to the discovery of an option. |
class |
CmdLineOptions.OptionException
A base class for options-related exceptions. |
static class |
CmdLineOptions.PropertiesFileParser
A CmdLineOptions.DefaultsStreamParser which interprets the stream as
coming from a Properties file.
|
static class |
CmdLineOptions.Resources
String resources for OptionException messages. |
Constructor Summary | |
CmdLineOptions()
Build an handler which recognizes options with the "-" prefix, allows only plain options, and fails if an option is not recognized. |
|
CmdLineOptions(boolean allowNegatedOptions)
Build an handler which recognizes options with the "-" prefix, specifies whether to allow or no the negation of options(by using +/- after the option itself), and fails if an option is not recognized. |
|
CmdLineOptions(boolean allowNegatedOptions,
java.lang.String optPrefix)
Build an handler which recognizes options with the given prefix, specifies whether to allow or no the negation of options(by using +/- after the option itself), and fails if an option is not recognized. |
|
CmdLineOptions(boolean allowNegatedOptions,
java.lang.String optPrefix,
boolean failOnUnrecognizedOption)
Build an handler which recognizes options with the given prefix and specifies whether to allow or no the negation of options(by using +/- after the option itself). |
|
CmdLineOptions(java.lang.String usageDescription)
Build an handler which recognizes options with the "-" prefix, allows only plain options, and fails if an option is not recognized. |
|
CmdLineOptions(java.lang.String usageDescription,
boolean allowNegatedOptions)
Build an handler which recognizes options with the "-" prefix, specifies whether to allow or no the negation of options(by using +/- after the option itself), and fails if an option is not recognized. |
|
CmdLineOptions(java.lang.String usageDescription,
boolean allowNegatedOptions,
java.lang.String optPrefix)
Build an handler which recognizes options with the given prefix, specifies whether to allow or no the negation of options(by using +/- after the option itself), and fails if an option is not recognized. |
|
CmdLineOptions(java.lang.String usageDescription,
boolean allowNegatedOptions,
java.lang.String optPrefix,
boolean failOnUnrecognizedOption)
Build an handler with the given usage description, which recognizes options with the given prefix and specifies whether to allow or no the negation of options(by using +/- after the option itself). |
Method Summary | |
void |
addAliases(java.lang.String aliases)
Add aliases to the last accessed option |
void |
addAliases(java.lang.String option,
java.lang.String aliases)
Adds aliases for a given option. |
java.lang.String |
getDescription(java.lang.String option)
Retrieve the description for a given option. |
java.lang.String |
getHelpOption()
Return the current help option See setHelpOption()
or null if no help option is set. |
CmdLineOptions.Handler.ParamSet |
hasOption(java.lang.String opt,
java.lang.String[] args)
Return the set of parameters of the given option. |
boolean |
isFailOnMixedHelpOptionEncountered()
Return the value for the 'failOnMixedHelpOptionEncountered' flag. |
boolean |
isFailOnUnrecognizedOption()
Return the failOnUnrecognizedOption. |
boolean |
isMandatory(java.lang.String option)
Returns the mandatory state of the given option. |
boolean |
isPrintUsageOnException()
|
static boolean |
isSortUsageOnPriority()
Return whether or not options are sorted also considering priority (besides alphabetical order) when usage() is called. |
java.lang.String[] |
parse(java.lang.String[] args)
Parse the cmdline arguments (usually received by main) looking for the options managed by the handler. |
java.lang.String[] |
parse(java.lang.String[] _args,
java.lang.String context)
Parses the cmdline arguments (usually received by main) looking for the options managed by the handler. |
void |
registerHandler(CmdLineOptions.Handler handler)
Registers an handler. |
void |
setActionOnParse(java.lang.Runnable action)
For non-user defined handlers, set an action to be executed when the last created option is parsed. |
void |
setActionOnParse(java.lang.String option,
java.lang.Runnable action)
For non-user defined handlers, set an action to be executed when the option is parsed. |
void |
setAlternativeMandatory(java.lang.String[] options)
Sets up a group of options, for which already exist handlers, as mutually exclusive and where at least one is mandatory. |
void |
setAlternativeMandatory(java.lang.String[] options,
boolean mandatory)
Sets/removes the mandatory state of a group of mutually exclusive options, for which already exist handlers, where at least one is mandatory. |
void |
setAlternativeMandatoryOnOption(java.lang.String options,
java.lang.String optionsToSet)
Specifies that one among the given options set become mandatory only if one option is encountered. |
void |
setAlternativeMandatoryOnOption(java.lang.String options,
java.lang.String[] optionsToSet)
Specifies that one among the given options set become mandatory only if one option is encountered. |
void |
setAlternativeMandatoryOnOptions(java.lang.String options,
java.lang.String optionsToSet)
Specifies that one among the given options set become mandatory only if one in another set of options is encountered. |
void |
setAlternativeMandatoryOnOptions(java.lang.String options,
java.lang.String[] optionsToSet)
Specifies that one among the given options set become mandatory only if one in another set of options is encountered. |
void |
setDescription(java.lang.String description)
Set the description for the last accessed option |
void |
setDescription(java.lang.String option,
java.lang.String description)
Sets the description for a given option. |
void |
setFailOnMixedHelpOptionEncountered(boolean failOnMixedHelpOptionEncountered)
Set the value for the 'failOnMixedHelpOptionEncountered' flag. |
void |
setFailOnUnrecognizedOption(boolean failOnUnrecognizedOption)
Set the failOnUnrecognizedOption. |
void |
setHelpOption()
|
void |
setHelpOption(java.lang.String option)
Set the given option an help option. |
void |
setHelpOption(java.lang.String option,
boolean value)
Set/unset an option as the "help option". |
void |
setMandatory()
Set the last accessed option as mandatory. |
void |
setMandatory(boolean mandatory)
Set or unset the 'mandatory' state of the last accessed option. |
void |
setMandatory(java.lang.String option)
Set an option as mandatory. |
void |
setMandatory(java.lang.String option,
boolean mandatory)
Set or unset the 'mandatory' state of an option. |
void |
setMandatoryOnOption(java.lang.String option,
java.lang.String optionsToSet)
Specifies that the given options set are mandatory only if one other option is encountered. |
void |
setMandatoryOnOption(java.lang.String option,
java.lang.String[] optionsToSet)
Specifies that all the options in the given set become mandatory only if one other option is encountered |
void |
setMandatoryOnOptions(java.lang.String options,
java.lang.String optionsToSet)
Specifies that the given options set are mandatory only if one in another set of options is encountered. |
void |
setMandatoryOnOptions(java.lang.String options,
java.lang.String[] optionsToSet)
Specifies that the given options set are mandatory only if one in another set of options is encountered. |
void |
setObjectOnOption(java.lang.String option,
java.lang.Object target)
Registers an handler which sets a member variable (of Object type) of on the target object when encountered, having the same name as the option, and no default value (null). |
void |
setObjectOnOption(java.lang.String option,
java.lang.Object target,
java.lang.Object defaultValue)
Registers an handler which sets a member variable (of Object type) of on the target object when encountered, having the same name as the option. |
void |
setObjectOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
java.lang.Object defaultValue)
Registers an handler which sets a member variable (of Object type) on the target object when encountered. |
void |
setObjectOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
java.lang.Object defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable (of Object type) of the target object when found (without defining any description nor aliases). |
void |
setObjectOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
java.lang.Object defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable (of Object type) of on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target)
Registers an handler which sets a member variable of String type, on the target object when encountered, having the same name as the option. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName)
Registers an handler which sets a member variable of String type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
boolean defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
boolean defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
byte defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
byte defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
char defaultValue)
Registers an handler which sets a member variable of char primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
char defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of char primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
double defaultValue)
Registers an handler which sets a member variable of double primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
double defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of double primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
float defaultValue)
Registers an handler which sets a member variable of float primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
float defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of float primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
int defaultValue)
Registers an handler which sets a member variable of int primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
int defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of int primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
long defaultValue)
Registers an handler which sets a member variable of long primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
long defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of long primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
short defaultValue)
Registers an handler which sets a member variable of short primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
short defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of short primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
java.lang.String defaultValue)
Registers an handler which sets a member variable of String type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.Object target,
java.lang.String memberName,
java.lang.String defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
boolean defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
boolean defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
byte defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
byte defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
char defaultValue)
Registers an handler which sets a member variable of char primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
char defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of char primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
double defaultValue)
Registers an handler which sets a member variable of double primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
double defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of double primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
float defaultValue)
Registers an handler which sets a member variable of float primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
float defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of float primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
int defaultValue)
Registers an handler which sets a member variable of int primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
int defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of int primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
long defaultValue)
Registers an handler which sets a member variable of long primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
long defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of long primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
short defaultValue)
Registers an handler which sets a member variable of short primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
short defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of short primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
java.lang.String defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
java.lang.String defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
boolean defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
boolean defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
byte defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
byte defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
char defaultValue)
Registers an handler which sets a member variable of char primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
char defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of char primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
double defaultValue)
Registers an handler which sets a member variable of double primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
double defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of double primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
float defaultValue)
Registers an handler which sets a member variable of float primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
float defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of float primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
int defaultValue)
Registers an handler which sets a member variable of int primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
int defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of int primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
long defaultValue)
Registers an handler which sets a member variable of long primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
long defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of long primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
short defaultValue)
Registers an handler which sets a member variable of short primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
short defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of short primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
java.lang.String defaultValue)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setOnOption(java.lang.String option,
java.lang.String description,
java.lang.String aliases,
java.lang.Object target,
java.lang.String memberName,
java.lang.String defaultValue,
boolean defaultOnly)
Registers an handler which sets a member variable of boolean primitive type on the target object when encountered. |
void |
setPrintUsageOnException(boolean printUsageOnException)
|
void |
setPriority(int priority)
Set the priority for the last accessed option |
void |
setPriority(java.lang.String option,
int priority)
Set the priority for a given option. |
static void |
setSortUsageOnPriority(boolean sortUsageOnPriority)
Set whether or not options are sorted also considering priority (besides alphabetical order) when usage() is called. |
void |
setValuesOnOptions(java.lang.String[] options,
java.lang.Object target,
java.lang.String member)
An overload for setValuesOnOptions() for String target members, that uses the
option literals themselves as option values.
|
void |
setValuesOnOptions(java.lang.String[] options,
java.lang.String[] values,
java.lang.Object target,
java.lang.String member)
Sets the same member with different values when different options are encountered. |
void |
setValuesOnOptions(java.lang.String options,
java.lang.Object target,
java.lang.String member)
An overload for setValuesOnOptions() for String target members, that uses the
option literals themselves as option values.
|
void |
setValuesOnOptions(java.lang.String options,
java.lang.String values,
java.lang.Object target,
java.lang.String member)
Sets the same member with different values when different options are encountered. |
java.lang.String |
usage()
Creates an usage string by combining the usage description provided at construction (if any) and the descriptions/aliases of every option. |
void |
useDefaultProperties(java.util.Properties properties)
|
void |
useDefaultPropertyFile(java.io.File propertiesFile)
Read the properties file containing the defaults. |
void |
useDefaultPropertyFile(java.io.File propertiesFile,
boolean required)
Read the properties file containing the defaults. |
void |
useDefaultPropertyFile(java.lang.String propertiesFile)
Set the properties file containing the defaults. |
void |
useDefaultPropertyFile(java.lang.String propertiesFile,
boolean required)
Set the properties file containing the defaults. |
void |
useDefaultStream(java.io.InputStream is,
CmdLineOptions.DefaultsStreamParser parser)
|
void |
useDefaultXMLFile(java.io.File XMLFile)
Read the XML file containing the defaults. |
void |
useDefaultXMLFile(java.io.File XMLFile,
boolean required)
Read the XML file containing the defaults. |
void |
useDefaultXMLFile(java.lang.String XMLFile)
Set the XML file containing the defaults. |
void |
useDefaultXMLFile(java.lang.String XMLFile,
boolean required)
Set the XML file containing the defaults. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CmdLineOptions(boolean allowNegatedOptions, java.lang.String optPrefix, boolean failOnUnrecognizedOption)
failOnUnrecognizedOption
- if true, a ProgrammingError will occur if an option is not recognized
by parse()
.optPrefix
- the prefix which identifies an option.allowNegatedOptions
- if true, options can be followed by +/- to switch them on or off.public CmdLineOptions(java.lang.String usageDescription, boolean allowNegatedOptions, java.lang.String optPrefix, boolean failOnUnrecognizedOption)
usageDescription
- a human-readable description of the tool embedding this objectfailOnUnrecognizedOption
- if true, a ProgrammingError will occur if an option is not recognized
by parse()
.optPrefix
- the prefix which identifies an option.allowNegatedOptions
- if true, options can be followed by +/- to switch them on or off.public CmdLineOptions(boolean allowNegatedOptions, java.lang.String optPrefix)
allowNegatedOptions
- if true, options can be followed by +/- to switch them on or off.optPrefix
- the prefix which identifies an option.public CmdLineOptions(java.lang.String usageDescription, boolean allowNegatedOptions, java.lang.String optPrefix)
usageDescription
- a human-readable description of the tool embedding this object.allowNegatedOptions
- if true, options can be followed by +/- to switch them on or off.optPrefix
- the prefix which identifies an option.public CmdLineOptions(java.lang.String usageDescription, boolean allowNegatedOptions)
usageDescription
- a human-readable description of the tool embedding this object.allowNegatedOptions
- if true, options can be followed by +/- to switch them on or off.public CmdLineOptions(java.lang.String usageDescription)
usageDescription
- a human-readable description of the tool embedding this object.public CmdLineOptions(boolean allowNegatedOptions)
allowNegatedOptions
- if true, options can be followed by +/- to switch them on or off.public CmdLineOptions()
Method Detail |
public boolean isPrintUsageOnException()
public void setPrintUsageOnException(boolean printUsageOnException)
public void useDefaultProperties(java.util.Properties properties)
public void useDefaultPropertyFile(java.io.File propertiesFile, boolean required)
propertiesFile
- the properties file to openrequired
- if true, an exception is thrown if the properties file is not foundpublic void useDefaultPropertyFile(java.io.File propertiesFile)
propertiesFile
- the properties file to openpublic void useDefaultPropertyFile(java.lang.String propertiesFile, boolean required)
propertiesFile
- the properties file to openrequired
- if true, an exception is thrown if the properties file is not foundpublic void useDefaultPropertyFile(java.lang.String propertiesFile)
propertiesFile
- the properties file to openpublic void useDefaultXMLFile(java.io.File XMLFile, boolean required)
XMLFile
- the XML file to openrequired
- if true, an exception is thrown if the XML file is not foundpublic void useDefaultXMLFile(java.io.File XMLFile)
XMLFile
- the XML file to openpublic void useDefaultXMLFile(java.lang.String XMLFile, boolean required)
XMLFile
- the XML file to openrequired
- if true, an exception is thrown if the XML file is not foundpublic void useDefaultXMLFile(java.lang.String XMLFile)
XMLFile
- the XML file to openpublic void useDefaultStream(java.io.InputStream is, CmdLineOptions.DefaultsStreamParser parser)
public java.lang.String[] parse(java.lang.String[] args)
Options are parsed according to their priority - options with higher priority are parsed first.
If the handlers has been built with the failOnUnrecognizedOption parameter true,
this method will throw an OptionException
on unrecognized
options.
args
- the cmdline arguments.
public java.lang.String[] parse(java.lang.String[] _args, java.lang.String context)
If the handlers has been built with the failOnUnrecognizedOption parameter true,
this method will throw an OptionException
on unrecognized
options.
context
- in case of parsing problem, it's used in the diagnostics
to tell the user the context of the problem (for example, if the parsing
is done on a String[] synthetized by the program and not directly on
command line arguments).
public java.lang.String usage()
public void setMandatory(java.lang.String option, boolean mandatory)
parse()
if they're not
included in the parsed arguments.
option
- the option whose mandatory state is to be set.mandatory
- the mandatory state to set.public void setMandatory(java.lang.String option)
parse()
if they're not
included in the parsed arguments.
option
- the option whose mandatory state is to be set.public void setMandatory()
parse()
if they're not
included in the parsed arguments.
public void setMandatory(boolean mandatory)
parse()
if they're not
included in the parsed arguments.
mandatory
- the mandatory state to set.public void setHelpOption(java.lang.String option, boolean value)
An "help option" is an option which the user uses when he wants only to receive help.
It affects the parsing in that, when parse()
is invoked, the parser will not complain about mandatory options
missing if the help option is the only one present.
If the help option is mixed with other options, the parsing result
(exceptional or correct) depend on the result of isFailOnMixedHelpOptionEncountered()
method (which defaults to true).
It is s client code responsability to react properly (for example displaying the
usage()
string) when the user specifies an help option.
option
- the option to be set or unset as help option.value
- if true, the given option is set as help option.
If false, the given option (which must be the current help
option) is unset as help option.public void setHelpOption(java.lang.String option)
See setHelpOption()
for details on help options.
option
- the option to be set as help option.public void setHelpOption()
public java.lang.String getHelpOption()
setHelpOption()
or null if no help option is set.
public boolean isMandatory(java.lang.String option)
option
- the option whose mandatory state is to be verified.
public void setAlternativeMandatory(java.lang.String[] options, boolean mandatory)
parse()
if at least one is included in the parsed arguments.
options
- an array of option names.mandatory
- the mandatory state.public void setMandatoryOnOption(java.lang.String option, java.lang.String[] optionsToSet)
option
- the option with triggers the mandatory state of the given others.optionsToSet
- the options which become mandatory.public void setMandatoryOnOption(java.lang.String option, java.lang.String optionsToSet)
option
- the option with triggers the mandatory state of the given others.optionsToSet
- the options which become mandatory, as a comma separated string.public void setMandatoryOnOptions(java.lang.String options, java.lang.String[] optionsToSet)
optionsToSet
- the options which become mandatory.public void setMandatoryOnOptions(java.lang.String options, java.lang.String optionsToSet)
optionsToSet
- the options which become mandatory, as a comma separated string.public void setAlternativeMandatoryOnOption(java.lang.String options, java.lang.String[] optionsToSet)
optionsToSet
- the options which become alternative-mandatory.public void setAlternativeMandatoryOnOption(java.lang.String options, java.lang.String optionsToSet)
optionsToSet
- the options which become alternative-mandatory, as a comma separated string.public void setAlternativeMandatoryOnOptions(java.lang.String options, java.lang.String[] optionsToSet)
optionsToSet
- the options which become alternative-mandatory.public void setAlternativeMandatoryOnOptions(java.lang.String options, java.lang.String optionsToSet)
optionsToSet
- the options which become alternative-mandatory, as a comma separated string.public void setAlternativeMandatory(java.lang.String[] options)
Alternative-mandatory options will
generate a ProgrammingError at runtime on parse()
if at least one is included in the parsed arguments.
options
- an array of option names.public void registerHandler(CmdLineOptions.Handler handler)
handler
- the option handler to register.public void setOnOption(java.lang.String option, java.lang.Object target)
option
- the option to be set.target
- the object which contains the member to be set.public void setObjectOnOption(java.lang.String option, java.lang.Object target, java.lang.Object defaultValue)
If the member type is boolean, the member will be set to true if the option exists. For other types, a single following parameter is required, unless a default is specified.
option
- the option to be set.target
- the object which contains the member to be set.defaultValue
- a default value of the member - may be null.public void setObjectOnOption(java.lang.String option, java.lang.Object target)
option
- the option and member name to be set.target
- the object which contains the member to be set.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.public void setObjectOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, java.lang.Object defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member - may be null.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, java.lang.String defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, boolean defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, char defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, byte defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, short defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, int defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, long defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, float defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, double defaultValue)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.public void setObjectOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, java.lang.Object defaultValue, boolean defaultOnly)
option
- the option to be set.description
- a description for the option.aliases
- the option aliases, in comma-separated format.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member - may be null.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setObjectOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, java.lang.Object defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member - may be null.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, java.lang.String defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, boolean defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, char defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, byte defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, short defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, int defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, long defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null) (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, float defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.Object target, java.lang.String memberName, double defaultValue, boolean defaultOnly)
option
- the option to be set.target
- the object which contains the member to be set.memberName
- the name of the member to be set.defaultValue
- a default value of the member.defaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null).public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, java.lang.String defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, boolean defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, char defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, byte defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, short defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, int defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, long defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null) (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, float defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, double defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, java.lang.String defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, boolean defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, char defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, byte defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, short defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, int defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, long defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, float defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String description, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, double defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, java.lang.String defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, boolean defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, char defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, byte defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, short defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, int defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, long defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null) (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, float defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, double defaultValue, boolean defaultOnly)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberdefaultOnly
- if true, the option will not allow parameters, but the associated member
will be set to the default if passed on the command line (defaultValue must be not null)public void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, java.lang.String defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, boolean defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, char defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, byte defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, short defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, int defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, long defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, float defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setOnOption(java.lang.String option, java.lang.String aliases, java.lang.Object target, java.lang.String memberName, double defaultValue)
option
- the option to be settarget
- the object which contains the member to be setmemberName
- the name of the member to be setdefaultValue
- a default value of the memberpublic void setValuesOnOptions(java.lang.String options, java.lang.String values, java.lang.Object target, java.lang.String member)
It's just a shortcut to multiple setOnOptions() calls referring to the same member in the target object and allowing only the default value to be set.
An example:
setValuesOnOptions("doThis, doThat", "this, that", this, "thingToDo");
sets the member "thingToDo" in the target (this
) to
either this or that when the user specifies either doThis
or doThat.
options
- the options which trigger the assignment, in comma separated formatvalues
- the values to assign the target object's member, in comma separated format,
in 1-1 correspondence with the optionstarget
- the target object, owning the member to be setmember
- the member variable to be set in the target object when one of the options
is encounteredpublic void setValuesOnOptions(java.lang.String[] options, java.lang.String[] values, java.lang.Object target, java.lang.String member)
It's just a shortcut to multiple setOnOptions() calls referring to the same member in the target object and allowing only the default value to be set.
An example:
setValuesOnOptions(new String[] { "doThis", "doThat" }, new String[] { "his", "that" }, this, "thingToDo");
sets the member "thingToDo" in the target (this
) to
either this or that when the user specifies either doThis
or doThat.
options
- the options which trigger the assignmentvalues
- the values to assign the target object's member, in 1-1 correspondence
with the optionstarget
- the target object, owning the member to be setmember
- the member variable to be set in the target object when one of the options
is encounteredpublic void setValuesOnOptions(java.lang.String options, java.lang.Object target, java.lang.String member)
setValuesOnOptions()
for String target members, that uses the
option literals themselves as option values.
The net effect is that the member target is set with the name of the option, whenever
one of the given options is specified by the user.
options
- the options which trigger the assignment, in comma separated formattarget
- the target object, owning the member to be setmember
- the member variable to be set in the target object when one of the options
is encounteredpublic void setValuesOnOptions(java.lang.String[] options, java.lang.Object target, java.lang.String member)
setValuesOnOptions()
for String target members, that uses the
option literals themselves as option values.
The net effect is that the member target is set with the name of the option, whenever
one of the given options is specified by the user.
options
- the options which trigger the assignment, in comma separated formattarget
- the target object, owning the member to be setmember
- the member variable to be set in the target object when one of the options
is encounteredpublic void setDescription(java.lang.String option, java.lang.String description)
option
- the option (for which an handler must already exist)description
- the description of the optionpublic void setDescription(java.lang.String description)
description
- the description of the optionpublic void setActionOnParse(java.lang.String option, java.lang.Runnable action)
CmdLineOptions.Handler#option(String, ParamSet, boolean)
).
The action will be executed when the option is parsed and the relative members are set.
option
- the option (for which an handler must already exist)action
- the action to execute (besides the automatic field-setting)public void setActionOnParse(java.lang.Runnable action)
CmdLineOptions.Handler#option(String, ParamSet, boolean)
).
The action will be executed when the option is parsed and the relative members are set.
action
- the action to execute (besides the automatic field-setting)public void setPriority(java.lang.String option, int priority)
option
- the option (for which an handler must already exist)public void setPriority(int priority)
priority
- the priority of the optionpublic CmdLineOptions.Handler.ParamSet hasOption(java.lang.String opt, java.lang.String[] args)
opt
- args
-
public java.lang.String getDescription(java.lang.String option)
option
- the option (for which an handler must exist)
public void addAliases(java.lang.String option, java.lang.String aliases)
option
- the option (for which an handler must already exist)aliases
- the new aliases for the option. If an alias is already set
it's ignored.public void addAliases(java.lang.String aliases)
aliases
- public boolean isFailOnUnrecognizedOption()
public void setFailOnUnrecognizedOption(boolean failOnUnrecognizedOption)
failOnUnrecognizedOption
- The failOnUnrecognizedOption to setpublic boolean isFailOnMixedHelpOptionEncountered()
OptionException
.
See setHelpOption()
for details on help options.
public void setFailOnMixedHelpOptionEncountered(boolean failOnMixedHelpOptionEncountered)
OptionException
.
See setHelpOption()
for details on help options.
failOnMixedHelpOptionEncountered
- The failOnMixedHelpOptionEncountered to setpublic static boolean isSortUsageOnPriority()
usage()
is called.
usage()
is called.public static void setSortUsageOnPriority(boolean sortUsageOnPriority)
usage()
is called.
sortUsageOnPriority
- if true, options are sorted also considering priority (besides alphabetical order)
when usage()
is called
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |