Class CommandLineOptions

java.lang.Object
  extended byCommandLineOptions

public class CommandLineOptions
extends java.lang.Object

Simple command line option parser. This will handle simple switches such as '-b' or longer switches such as '--break=on'.

Author:
Michael McTernan, Michael.McTernan.2001@cs.bris.ac.uk

Constructor Summary
CommandLineOptions(java.lang.String[] args)
          Create a CommandLineOptions object to represent the options parsed from some argument list.
 
Method Summary
 void addOption(java.lang.String swtch, java.lang.Object key, java.lang.String description)
          Add a single of option for some key.
 void addOption(java.lang.String swtch0, java.lang.String swtch1, java.lang.Object key, java.lang.String description)
          Add a pair of options for the same key.
 java.lang.String get(java.lang.String key)
          Get the value for some command line option as a String.
 java.lang.String toString()
          Return a String describing the options contained within this map.
 java.lang.String usage()
          Display usage information for each command line switch.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandLineOptions

public CommandLineOptions(java.lang.String[] args)
Create a CommandLineOptions object to represent the options parsed from some argument list.

Parameters:
args - The argument list to parse.
Method Detail

addOption

public void addOption(java.lang.String swtch,
                      java.lang.Object key,
                      java.lang.String description)
Add a single of option for some key. This can be called multiple times as needed if more than one switch is required to control the value of a single key.

Parameters:
swtch - The first switch that sets a value to associate with key.
key - An object with which switch values will be associated, which should also be used to retrieve option values with the get() method.
description - Description of what is controlled by the switch. This is used for the switch descriptions provided by usage().

addOption

public void addOption(java.lang.String swtch0,
                      java.lang.String swtch1,
                      java.lang.Object key,
                      java.lang.String description)
Add a pair of options for the same key. This can be used to conveniently set a long and short form of a command line switch where both switches control the same key value.

Parameters:
swtch0 - The first switch that sets a value to associate with key.
swtch1 - A second switch that sets a value to associate with key.
key - An object with which switch values will be associated, which should also be used to retrieve option values with the get() method.
description - Description of what is controlled by the switch. This is used for the switch descriptions provided by usage().

get

public java.lang.String get(java.lang.String key)
Get the value for some command line option as a String.

Parameters:
key - A key that may have had some value associated with it.
Returns:
Either a String being the supplied commandline value or null if the option was not specified.

usage

public java.lang.String usage()
Display usage information for each command line switch.


toString

public java.lang.String toString()
Return a String describing the options contained within this map.