|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.mrami.libre.GetOpt.GetOpt
Simple class for doing command line argument processing.
-a) and long (
--freakin-long-option) options.-abqv), and if
any options take parameters, those will be read in sequence from the command
line following the glommage.--) is recognized
and handled.System.err.add...()processParams()get...Value()An example of the automatic usage statement (as rendered by a standard printStackTrace()):
com.mrami.libre.GetOpt.CommandLineOptionException: error: Unknown option: -? error: required option --output-dir was not given usage: com.mrami.libre.ClassGenerator.Output.JavaNoMiddle -d <directory> [ -D <type> ] where: -d, --output-dir <directory>: (required) output the new classes/hierarchy to <directory> -D, --date-type <type>: the type to use for dates (default: javax.sql.Date) at com.mrami.libre.GetOpt.GetOpt.processParams(GetOpt.java:459) at com.mrami.libre.ClassGenerator.Output.JavaNoMiddle.setParams(JavaNoMiddle.java:80) at com.mrami.libre.ClassGenerator.Generate.main(Generate.java:72)
And the code that generated it:
GetOpt opts = new GetOpt(getClass().getName());
opts.addParam('d', "output-dir", "directory",
"output the new classes/hierarchy to <directory>", true);
opts.addParam('D', "date-type", "type", "the type to use for dates (default: "
+ m_DateType + ")", false);
opts.processParams(Options);
| Constructor Summary | |
GetOpt(java.lang.Class clazz)
Constructor. |
|
GetOpt(java.lang.String ProgName)
Constructor. |
|
| Method Summary | |
int |
addFlag(java.lang.Character ShortOpt,
java.lang.String LongOpt,
java.lang.String Documentation)
Add a flag-type option (true or false) |
int |
addFlag(char ShortOpt,
java.lang.String LongOpt,
java.lang.String Documentation)
Add a flag-type option (true or false) |
int |
addParam(java.lang.Character ShortOpt,
java.lang.String LongOpt,
java.lang.String ParamMnemonic,
java.lang.String Documentation,
boolean Required)
Add a parameter-type option (with a value to be passed in). |
int |
addParam(char ShortOpt,
java.lang.String LongOpt,
java.lang.String ParamMnemonic,
java.lang.String Documentation,
boolean Required)
Add a parameter-type option (with a value to be passed in). |
boolean |
getFlagValue(char ch)
Retrieve a flag. |
boolean |
getFlagValue(java.lang.String o)
Retrieve a flag. |
java.lang.String |
getParamValue(char ch)
Retrieve a parameter by short option |
java.lang.String |
getParamValue(char ch,
java.lang.String Default)
Retrieve a parameter by short option (with default value) |
java.lang.String |
getParamValue(java.lang.String o)
Retrieve a parameter by long option |
java.lang.String |
getParamValue(java.lang.String o,
java.lang.String Default)
Retrieve a parameter by long option (with default value) |
java.util.ArrayList |
processParams(java.util.ArrayList Params)
Process the command line |
java.util.ArrayList |
processParams(java.lang.String[] Params)
Process the command line |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public GetOpt(java.lang.String ProgName)
ProgName - The name of the program (for the usage message)public GetOpt(java.lang.Class clazz)
clazz - The class name of the program (for the usage message)| Method Detail |
public int addFlag(char ShortOpt,
java.lang.String LongOpt,
java.lang.String Documentation)
ShortOpt - Optional one-character option value (no dash). May be null.LongOpt - Optional GNU style long option. DO NOT include the
beginning '--'. May be null.Documentation - Documentation to display when generating the usage message.
May not be null.
java.lang.IllegalArgumentException - if both ShortOpt and LongOpt are null
java.lang.IllegalArgumentException - if Documentation is null or zero length (Work with me here!
I'm building a freakin' usage message for you!)
java.lang.IllegalArgumentException - if either ShortOpt or LongOpt has already been added
public int addFlag(java.lang.Character ShortOpt,
java.lang.String LongOpt,
java.lang.String Documentation)
ShortOpt - Optional one-character option value (no dash). May be null.LongOpt - Optional GNU style long option. DO NOT include the
beginning '--'. May be null.Documentation - Documentation to display when generating the usage message.
May not be null.
java.lang.IllegalArgumentException - if both ShortOpt and LongOpt are null
java.lang.IllegalArgumentException - if Documentation is null or zero length (Work with me here!
I'm building a freakin' usage message for you!)
java.lang.IllegalArgumentException - if either ShortOpt or LongOpt has already been added
public int addParam(char ShortOpt,
java.lang.String LongOpt,
java.lang.String ParamMnemonic,
java.lang.String Documentation,
boolean Required)
ShortOpt - Optional one-character option value (no dash). May be null.LongOpt - Optional GNU style long option. DO NOT include the
beginning '--'. May be null.ParamMnemonic - A short name for the parameter. May not be null.Documentation - Documentation to display when generating the usage message.
May not be null.Required - Whether the flag is required.
java.lang.IllegalArgumentException - if both ShortOpt and LongOpt are null
java.lang.IllegalArgumentException - if Documentation is null or zero length
java.lang.IllegalArgumentException - if ParamMnemonic is null or zero length
java.lang.IllegalArgumentException - if either ShortOpt or LongOpt has already been added
public int addParam(java.lang.Character ShortOpt,
java.lang.String LongOpt,
java.lang.String ParamMnemonic,
java.lang.String Documentation,
boolean Required)
ShortOpt - Optional one-character option value (no dash). May be null.LongOpt - Optional GNU style long option. DO NOT include the
beginning '--'. May be null.ParamMnemonic - A short name for the parameter. May not be null.Documentation - Documentation to display when generating the usage message.
May not be null.Required - Whether the flag is required.
java.lang.IllegalArgumentException - if both ShortOpt and LongOpt are null
java.lang.IllegalArgumentException - if Documentation is null or zero length
java.lang.IllegalArgumentException - if ParamMnemonic is null or zero length
java.lang.IllegalArgumentException - if either ShortOpt or LongOpt has already been added
public java.util.ArrayList processParams(java.lang.String[] Params)
throws CommandLineOptionException
Params - The command line parameters
CommandLineOptionException - if any of the command line processing semantics are violated.
The message will contain a usage message in traditional unix
style.
public java.util.ArrayList processParams(java.util.ArrayList Params)
throws CommandLineOptionException
Params - The command line parameters
CommandLineOptionException - if any of the command line processing semantics are violated
public java.lang.String getParamValue(char ch)
throws OptionProcessingException
ch - The short option version of the parameter to fetch
java.lang.ArrayIndexOutOfBoundsException - if the index does not exist
OptionProcessingException - if the index was a flag and not a parameter
public java.lang.String getParamValue(char ch,
java.lang.String Default)
throws OptionProcessingException
ch - The short option version of the parameter to fetchDefault - The value to return if the parameter was not passed
java.lang.ArrayIndexOutOfBoundsException - if the index does not exist
OptionProcessingException - if the index was a flag and not a parameter
public java.lang.String getParamValue(java.lang.String o)
throws OptionProcessingException
o - The long option version of the parameter to fetch
java.lang.ArrayIndexOutOfBoundsException - if the index does not exist
OptionProcessingException - if the index was a flag and not a parameter
public java.lang.String getParamValue(java.lang.String o,
java.lang.String Default)
throws OptionProcessingException
o - The long option version of the parameter to fetchDefault - The value to return if the parameter was not passed
java.lang.ArrayIndexOutOfBoundsException - if the index does not exist
OptionProcessingException - if the index was a flag and not a parameter
public boolean getFlagValue(char ch)
throws OptionProcessingException
ch - The short option version of the parameter to fetch
java.lang.ArrayIndexOutOfBoundsException - if the index does not exist
OptionProcessingException - if the index was a parameter and not a flag
public boolean getFlagValue(java.lang.String o)
throws OptionProcessingException
o - The long option version of the parameter to fetch
java.lang.ArrayIndexOutOfBoundsException - if the index does not exist
OptionProcessingException - if the index was a parameter and not a flag
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||