maslab.util
Class GetOpt

java.lang.Object
  extended by maslab.util.GetOpt

public class GetOpt
extends java.lang.Object

A basic GetOpt implementation. Add your options, parse the command line arguments, then get the modified value of your arguments.


Field Summary
 int helpMessageWidth
           
 
Constructor Summary
GetOpt()
          Create an empty GetOpt object.
 
Method Summary
 void addBoolean(char sname, java.lang.String lname, boolean defaultValue, java.lang.String helpMessage)
          Add a boolean-type option.
 void addDouble(char sname, java.lang.String lname, double defaultValue, java.lang.String helpMessage)
          Add an double-type option.
 void addInt(char sname, java.lang.String lname, int defaultValue, java.lang.String helpMessage)
          Add an integer-type option.
 void addString(char sname, java.lang.String lname, java.lang.String defaultValue, java.lang.String helpMessage)
          Add a string-type option.
 void doHelp()
          Output a "pretty" usage display based on the helpMessages of each option.
 void doHelp(java.io.Writer outs)
          Output a "pretty" usage display based on the helpMessages of each option; sends the output to the specified Writer.
 void dump()
          As a debugging aid, dump the values of all options to stdout.
 void dumpInternal(java.io.Writer outs)
          As a debugging aid, dump the values of all options to the specified Writer..
 boolean getBoolean(java.lang.String lname)
          Determine the value of an option.
 double getDouble(java.lang.String lname)
          Determine the value of an option.
 java.util.ArrayList<java.lang.String> getExtraArgs()
          Return arguments that were not consumed by flag processing.
 int getInt(java.lang.String lname)
          Determine the value of an option.
 java.lang.String getReason()
          Get the reason for an error.
 java.lang.String getString(java.lang.String lname)
          Determine the value of an option.
static void main(java.lang.String[] args)
          Simple sample code to show how to use the library.
 boolean parse(java.lang.String[] args)
          Process command line arguments, updating the options we know about.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

helpMessageWidth

public int helpMessageWidth
Constructor Detail

GetOpt

public GetOpt()
Create an empty GetOpt object. You should add options, then parse, then get the values.

Method Detail

getReason

public java.lang.String getReason()
Get the reason for an error. The error is "user friendly"


addString

public void addString(char sname,
                      java.lang.String lname,
                      java.lang.String defaultValue,
                      java.lang.String helpMessage)
Add a string-type option. The value can be determined (after parsing) by the matching getValue method.

Parameters:
sname - A one letter short name or 0 if none.
lname - A multi-letter option name
defaultValue - The default value of the option
helpMessage - A brief description of the option

getString

public java.lang.String getString(java.lang.String lname)
Determine the value of an option.

Parameters:
lname - The long name specified by the matching addOption method.

addInt

public void addInt(char sname,
                   java.lang.String lname,
                   int defaultValue,
                   java.lang.String helpMessage)
Add an integer-type option. The value can be determined (after parsing) by the matching getValue method.

Parameters:
sname - A one letter short name or 0 if none.
lname - A multi-letter option name
defaultValue - The default value of the option
helpMessage - A brief description of the option

addDouble

public void addDouble(char sname,
                      java.lang.String lname,
                      double defaultValue,
                      java.lang.String helpMessage)
Add an double-type option. The value can be determined (after parsing) by the matching getValue method.

Parameters:
sname - A one letter short name or 0 if none.
lname - A multi-letter option name
defaultValue - The default value of the option
helpMessage - A brief description of the option

getInt

public int getInt(java.lang.String lname)
Determine the value of an option.

Parameters:
lname - The long name specified by the matching addOption method.

getDouble

public double getDouble(java.lang.String lname)
Determine the value of an option.

Parameters:
lname - The long name specified by the matching addOption method.

addBoolean

public void addBoolean(char sname,
                       java.lang.String lname,
                       boolean defaultValue,
                       java.lang.String helpMessage)
Add a boolean-type option. The value can be determined (after parsing) by the matching getValue method.

Parameters:
sname - A one letter short name or 0 if none.
lname - A multi-letter option name
defaultValue - The default value of the option
helpMessage - A brief description of the option

getBoolean

public boolean getBoolean(java.lang.String lname)
Determine the value of an option.

Parameters:
lname - The long name specified by the matching addOption method.

parse

public boolean parse(java.lang.String[] args)
Process command line arguments, updating the options we know about.

Parameters:
args - The args passed into the main() function.
Returns:
success. On failure, false is returned and getReason() will tell you about the error.

getExtraArgs

public java.util.ArrayList<java.lang.String> getExtraArgs()
Return arguments that were not consumed by flag processing.


dump

public void dump()
As a debugging aid, dump the values of all options to stdout.


dumpInternal

public void dumpInternal(java.io.Writer outs)
                  throws java.io.IOException
As a debugging aid, dump the values of all options to the specified Writer..

Throws:
java.io.IOException

doHelp

public void doHelp()
Output a "pretty" usage display based on the helpMessages of each option.


doHelp

public void doHelp(java.io.Writer outs)
            throws java.io.IOException
Output a "pretty" usage display based on the helpMessages of each option; sends the output to the specified Writer.

Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
Simple sample code to show how to use the library.