public class CmdLineArgs
extends java.lang.Object
String[] args),
for example to merge several sets of option specifications.
An option consists of a key arg and 0...many value arguments.
The method parseArgs will attempt to guess which arguments
are keys and which are values, e.g. looking for a "-" prefix.
This class can therefore be used for unknown sets of options.
To avoid fooling the algorithm with weird values (like "-273"), the expected
option keys with their minimum number of values can be specified using the
registerOption methods.
This mechanism can later be extended to allow validation of required arguments.
TODO: logging and error handling
| Constructor and Description |
|---|
CmdLineArgs() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String[] |
getAllArgs()
Returns all arguments (both options and values).
|
CmdLineOption[] |
getRecognizedArgs()
Gets all arguments that were recognized by the parser.
|
java.lang.String[] |
getValues(CmdLineOption clo) |
boolean |
isSpecified(CmdLineRegisteredOption clo)
Returns
true if the given option clo appeared in the argument lists that were
passed to parseArgs; false otherwise. |
void |
parseArgs(java.lang.String[] args)
If called more than once without calling
reset() in between,
the options are merged in the style of a Map. |
void |
registerOption(CmdLineRegisteredOption opt) |
void |
registerOption(java.lang.String name,
int minValuesCount) |
void |
reset() |
public void reset()
public void registerOption(java.lang.String name,
int minValuesCount)
public void registerOption(CmdLineRegisteredOption opt)
public void parseArgs(java.lang.String[] args)
reset() in between,
the options are merged in the style of a Map.args - public java.lang.String[] getAllArgs()
public CmdLineOption[] getRecognizedArgs()
getValues(CmdLineOption).public boolean isSpecified(CmdLineRegisteredOption clo)
true if the given option clo appeared in the argument lists that were
passed to parseArgs; false otherwise.clo - public java.lang.String[] getValues(CmdLineOption clo)