|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.bbn.openmap.util.ArgParser
public class ArgParser
A simple class to manage the line arguments of a program. Takes the String[] argv that is provided to the main method of a class, and separates them out, depending on the options given to the ArgParser. After you create the parser, add your options that you want.
Nested Class Summary | |
---|---|
class |
ArgParser.Arg
A default version of the Arg class used to represent options for the ArgParser to use. |
class |
ArgParser.HelpArg
A Arg class to spur off help messages. |
Field Summary | |
---|---|
protected boolean |
allowAbbr
Tells the Args to accept the first letter of their name for argv options specified with one letter. |
protected java.util.Vector |
args
The Args that the parser is looking for. |
protected char |
option
The character flag for an option. |
protected java.lang.String |
programName
The program name that's using the parser. |
protected java.lang.String[] |
rest
The String array that holds all of the leftover argvs. |
static int |
TO_END
The length to submit if you want a variable length list at the end of the command line, like all the arguments left over. |
Constructor Summary | |
---|---|
ArgParser(java.lang.String pName)
Create a parser for the named program. |
Method Summary | |
---|---|
void |
add(java.lang.String argName,
java.lang.String desc)
Add a argument to the parser. |
void |
add(java.lang.String argName,
java.lang.String desc,
int expectedNumberOfArguments)
Add a argument to the parser. |
void |
add(java.lang.String argName,
java.lang.String desc,
int expectedNumberOfArguments,
boolean expectDashedArguments)
Add a argument to the parser. |
void |
bail(java.lang.String message,
boolean printUsageStatement)
Called if something is messed up. |
boolean |
getAllowAbbr()
|
ArgParser.Arg |
getArg(java.lang.String name)
Return a Arg object with a particular name. |
java.util.Vector |
getArgs()
|
java.lang.String[] |
getArgValues(java.lang.String name)
Given an Arg name, return the values. |
java.lang.String[] |
getRest()
|
static void |
main(java.lang.String[] argv)
|
boolean |
parse(java.lang.String[] argv)
Parse and organize the array of Strings. |
void |
printUsage()
Print a list of options added to the parser. |
void |
setAllowAbbr(boolean set)
Tell the parser to accept first-letter representations of the options. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int TO_END
protected java.lang.String programName
protected java.util.Vector args
protected java.lang.String[] rest
protected char option
protected boolean allowAbbr
Constructor Detail |
---|
public ArgParser(java.lang.String pName)
pName
- the program name.Method Detail |
---|
public void add(java.lang.String argName, java.lang.String desc)
argName
- the command line optiondesc
- a help line description.public void add(java.lang.String argName, java.lang.String desc, int expectedNumberOfArguments)
argName
- the command line optiondesc
- a help line description.expectedNumberOfArguments
- the number of option parameters expected
for this option.public void add(java.lang.String argName, java.lang.String desc, int expectedNumberOfArguments, boolean expectDashedArguments)
argName
- the command line optiondesc
- a help line description.expectedNumberOfArguments
- the number of option parameters expected
for this option.expectDashedArguments
- tell the parser that this option may have
arguments that may start with dashes, for instance, a negative
number. False by default.public boolean parse(java.lang.String[] argv)
argv
- arguments to be parsed
public void bail(java.lang.String message, boolean printUsageStatement)
message
- a message to display.printUsageStatement
- true to display a list of available optionspublic void setAllowAbbr(boolean set)
set
- true to acceptpublic boolean getAllowAbbr()
public java.util.Vector getArgs()
public ArgParser.Arg getArg(java.lang.String name)
name
- of Arg
public java.lang.String[] getArgValues(java.lang.String name)
name
- key string for values
public java.lang.String[] getRest()
public void printUsage()
public static void main(java.lang.String[] argv)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |