public class ArgParser
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
ArgParser(java.lang.String pName)
Create a parser for the named program.
|
Modifier and Type | Method and Description |
---|---|
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()
Tells whether the parser accepts first-letter representations of the
options.
|
ArgParser.Arg |
getArg(java.lang.String name)
Return a Arg object with a particular name.
|
java.util.Vector |
getArgs()
Returns a Vector of Arg objects.
|
java.lang.String[] |
getArgValues(java.lang.String name)
Given an Arg name, return the values.
|
java.lang.String[] |
getRest()
Get the String[] that makes up the trailing Strings after the options
were parsed.
|
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.
|
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
public ArgParser(java.lang.String pName)
pName
- the program name.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)
public void bail(java.lang.String message, boolean printUsageStatement)
message
- a message to display.printUsageStatement
- true to display a list of available options.public void setAllowAbbr(boolean set)
public boolean getAllowAbbr()
public java.util.Vector getArgs()
public ArgParser.Arg getArg(java.lang.String name)
public java.lang.String[] getArgValues(java.lang.String name)
public java.lang.String[] getRest()
public void printUsage()
public static void main(java.lang.String[] argv)
Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details