## org.das2.util.ArgumentList

Utility class for processing the String[] arguments passed into the main routine, handing positional and switch parameters. Also automatically generates the usage documentation. Note in Autoplot's pngwalk, we add a parameter and positional argument with the same name. This should continue to be supported.

## ArgumentList( String programName )

creates the processor for the program. `programName` is provided for the usage statement. After creating the object, arguments are specified one by one, and then the process method is called.

## FALSE

## TRUE

## addBooleanSwitchArgument

addBooleanSwitchArgument( String name, String abbrev, String key, String description ) → void

specify a named switch argument that is named, and we only care whether it was used or not. e.g. --debug

### Parameters

name - the long parameter name, which the user may enter. e.g. "level"
abbrev - short (one letter) parameter version. e.g. "l" for -l=3
key - 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.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## addOptionalPositionArgument

addOptionalPositionArgument( int position, String key, String defaultValue, String description ) → void

Specify the ith positional argument, which may be left unspecified by the user. Note that all positional arguments after this one must also be optional.

### Parameters

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.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## addOptionalSwitchArgument

addOptionalSwitchArgument( String name, String abbrev, String key, String defaultValue, String description ) → void

specify a named switch argument that may be specified by the user. For example, --level=3 or -l=3

### Parameters

name - the long parameter name, which the user may enter. e.g. "level"
abbrev - short (one letter) parameter version. e.g. "l" for -l=3
key - the internal reference name to get the value specified, not necessarily but often the same as name.
defaultValue - 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 value
description - a short (40 character) description of the argument.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## addPositionArgument

addPositionArgument( int position, String key, String description ) → void

Specify the ith positional argument.

### Parameters

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.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## addSwitchArgument

addSwitchArgument( String name, String abbrev, String key, String description ) → void

specify a named switch argument that must be specified by the user. For example, --level=3 or -l=3

### Parameters

name - the long parameter name, which the user may enter. e.g. "level"
abbrev - short (one letter) parameter version. e.g. "l" for -l=3
key - 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.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getBooleanValue

getBooleanValue( String key ) → boolean

### Parameters

key - a String

### Returns:

boolean
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getExitCode

getExitCode( ) → int

return 0 if the exit code for a checkArgs()==false is 0 or non-zero. It will be 0 if --help was used.

### Returns:

the exit code.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getMap

getMap( ) → java.util.Map

return a Map of all the specified values. The keys are all the internal String keys, and the values are all Strings.

### Returns:

a Map of the specified values, including defaults.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getOptions

getOptions( ) → java.util.Map

returns a Map of optional arguments that were specified, so you can see exactly what was specified.

### Returns:

a Map of the specified values, without defaults.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getPreferences

getPreferences( ) → java.util.prefs.Preferences

returns the options as a java.util.prefs.Preferences object, for batch processes. The idea is that a process which grabs default settings from the user Preferences can instead get them from the command line, to support batch processes. See the Vg1pws app for an example of how this is used.

### Returns:

a Preferences object, loaded with the command line values.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## getValue

getValue( String key ) → String

get the value for this parameter

### Parameters

key - the argument identifier.

### Returns:

the parameter's value.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## logPrefsSettings

logPrefsSettings( java.util.logging.Logger logger ) → void

dump the configuration to the given logger at Level.CONFIG.

### Parameters

logger - a Logger

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## makeFileReferenceAbsolute

makeFileReferenceAbsolute( String ref ) → String

make a standard way to make file names absolute

### Parameters

ref - e.g. files/afile/foo.txt

### Returns:

/home/jbf/data/files/afile/foo.txt because PWD is /home/jbf/data
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## printPrefsSettings

printPrefsSettings( ) → void

see Vg1pws app for example use.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## printUsage

printUsage( ) → void

print the usage statement out to stderr.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## process

process( String[] args ) → boolean

given the specification, process the argument list. If the list is in error, the usage statement is generated, and the System.exit is called (sorry!). Otherwise the method returns and getValue() may be used to retrieve the values. Again, note that System.exit may be called. This is probably a bad idea and another method will probably be added that would return true if processing was successful.

### Parameters

args - as in public static void main( String[] args ).

### Returns:

false if System.exit should be called.
[search for examples] [view on GitHub] [view on old javadoc] [view source]

## requireOneOf

requireOneOf( String[] keyNames ) → void

requires the user specify one of these values, otherwise the usage statement is printed.

### Parameters

keyNames - an array of internal key names that identify parameters.

### Returns:

void (returns nothing)
[search for examples] [view on GitHub] [view on old javadoc] [view source]