public class ArgumentList
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FALSE |
static java.lang.String |
TRUE |
Constructor and Description |
---|
ArgumentList(java.lang.String programName)
creates the processor for the program.
|
Modifier and Type | Method and Description |
---|---|
void |
addBooleanSwitchArgument(java.lang.String name,
java.lang.String abbrev,
java.lang.String key,
java.lang.String description)
specify a named switch argument that is named, and we only care whether it was used or not.
|
void |
addOptionalPositionArgument(int position,
java.lang.String key,
java.lang.String defaultValue,
java.lang.String description)
Specify the ith positional argument, which may be left unspecified by
the user.
|
void |
addOptionalSwitchArgument(java.lang.String name,
java.lang.String abbrev,
java.lang.String key,
java.lang.String defaultValue,
java.lang.String description)
specify a named switch argument that may be specified by the user.
|
void |
addPositionArgument(int position,
java.lang.String key,
java.lang.String description)
Specify the ith positional argument.
|
void |
addSwitchArgument(java.lang.String name,
java.lang.String abbrev,
java.lang.String key,
java.lang.String description)
specify a named switch argument that must be specified by the user.
|
boolean |
getBooleanValue(java.lang.String key) |
int |
getExitCode()
return 0 if the exit code for a checkArgs()==false is 0 or non-zero.
|
java.util.Map<java.lang.String,java.lang.String> |
getMap()
return a Map of all the specified values.
|
java.util.Map<java.lang.String,java.lang.String> |
getOptions()
returns a Map of optional arguments that were specified, so you can see
exactly what was specified.
|
java.util.prefs.Preferences |
getPreferences()
returns the options as a java.util.prefs.Preferences object, for
batch processes.
|
java.lang.String |
getValue(java.lang.String key)
get the value for this parameter
|
void |
logPrefsSettings(java.util.logging.Logger logger)
dump the configuration to the given logger at Level.CONFIG.
|
static java.lang.String |
makeFileReferenceAbsolute(java.lang.String ref)
make a standard way to make file names absolute
|
void |
printPrefsSettings()
see Vg1pws app for example use.
|
void |
printUsage()
print the usage statement out to stderr.
|
boolean |
process(java.lang.String[] args)
given the specification, process the argument list.
|
void |
requireOneOf(java.lang.String[] keyNames)
requires the user specify one of these values, otherwise the usage
statement is printed.
|
public static final java.lang.String FALSE
public static final java.lang.String TRUE
public ArgumentList(java.lang.String programName)
programName
- the program namepublic java.lang.String getValue(java.lang.String key)
key
- the argument identifier.java.lang.IllegalArgumentException
- if the parameter name was never described.public static java.lang.String makeFileReferenceAbsolute(java.lang.String ref)
ref
- e.g. files/afile/foo.txtpublic java.util.prefs.Preferences getPreferences()
public boolean getBooleanValue(java.lang.String key)
public void addPositionArgument(int position, java.lang.String key, java.lang.String description)
position
- the position number, 0 is the first argument position after the class name.key
- the internal reference name to get the value specified.description
- a short (40 character) description of the argument.public void requireOneOf(java.lang.String[] keyNames)
keyNames
- an array of internal key names that identify parameters.public void addOptionalPositionArgument(int position, java.lang.String key, java.lang.String defaultValue, java.lang.String description)
position
- the position number, 0 is the first argument position after the class name.key
- the internal reference name to get the value specified.defaultValue
- the value that is returned if a value is not provided by the user.description
- a short (40 character) description of the argument.public void addSwitchArgument(java.lang.String name, java.lang.String abbrev, java.lang.String key, java.lang.String description)
name
- the long parameter name, which the user may enter. e.g. "level"abbrev
- short (one letter) parameter version. e.g. "l" for -l=3key
- the internal reference name to get the value specified, not necessarily but often the same as name.description
- a short (40 character) description of the argument.public void addOptionalSwitchArgument(java.lang.String name, java.lang.String abbrev, java.lang.String key, java.lang.String defaultValue, java.lang.String description)
name
- the long parameter name, which the user may enter. e.g. "level"abbrev
- short (one letter) parameter version. e.g. "l" for -l=3defaultValue
- value to return if the user doesn't specify. If TRUE or FALSE is used, then the
user may use a number of different inputs such as "T" or "true", and getBooleanValue can be used to read the valuekey
- the internal reference name to get the value specified, not necessarily but often the same as name.description
- a short (40 character) description of the argument.public void addBooleanSwitchArgument(java.lang.String name, java.lang.String abbrev, java.lang.String key, java.lang.String description)
name
- the long parameter name, which the user may enter. e.g. "level"abbrev
- short (one letter) parameter version. e.g. "l" for -l=3key
- the internal reference name to get the value specified, not necessarily but often the same as name.description
- a short (40 character) description of the argument.public void printUsage()
public int getExitCode()
public java.util.Map<java.lang.String,java.lang.String> getMap()
public java.util.Map<java.lang.String,java.lang.String> getOptions()
public boolean process(java.lang.String[] args)
args
- as in public static void main( String[] args ).public void printPrefsSettings()
public void logPrefsSettings(java.util.logging.Logger logger)
logger
-