|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | CONST | FIELD | CONSTR | METHOD | DETAIL: CONST | FIELD | CONSTR | METHOD | ||||||||
|
PROTOTYPE Not reviewed yet: use at your own risk! |
java.lang.Object | +--satin.common.CommandLine
public class CommandLine
extends java.lang.Object
A simple command line parser for use with the string array passed
to main methods.
| Inner Class Summary | |
static class |
CommandLine.SyntaxError
Indicates a syntax error in a command line. |
| Constructor Summary | |
CommandLine(java.lang.String[] mainArgv)
Constructs a command line object from the argument list from a main method. |
|
| Method Summary | |
int |
findArg(java.lang.String name)
Searches the command line for the first occurrence of name
and returns its index or -1. |
void |
finish()
Call this when argument parsing is finished. |
boolean |
getArg(java.lang.String name)
Gets an unvalued argument from the command line. |
java.lang.String |
getArgValue(java.lang.String name,
java.lang.String descr)
Searches the command line for the first occurrence of name
and a following value. |
boolean |
getHelpArg()
Searches the command line for all the common "help" switches: "-h", "-?", "/h", "/?", "-help", "/help". |
int |
getIntArg(java.lang.String name,
java.lang.String descr,
int dflt)
Gets an argument from the command line that has an integer value. |
java.lang.String[] |
getRemaining()
Returns the remaining (unparsed) arguments in the command line. |
java.lang.String |
getStringArg(java.lang.String name,
java.lang.String descr,
java.lang.String dflt)
Gets an argument from the command line that has a string value. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public CommandLine(java.lang.String[] mainArgv)
main method.| Method Detail |
public java.lang.String[] getRemaining()
public void finish()
throws CommandLine.SyntaxError
SyntaxError if there are any leftover arguments.public boolean getArg(java.lang.String name)
name.
If it is found, it is removed from the command line and
true is returned. Otherwise false is returned.
name
public java.lang.String getStringArg(java.lang.String name,
java.lang.String descr,
java.lang.String dflt)
throws CommandLine.SyntaxError
name.
If name is not found, dflt is returned.
If name is found, the argument immediately following
it is returned (without modification), and the argument and its
value are removed from the command line.
If there is no argument immediately following it, a
SyntaxError is thrown.
namedescrdflt
public int getIntArg(java.lang.String name,
java.lang.String descr,
int dflt)
throws CommandLine.SyntaxError
name.
If name is not found, dflt is returned.
If name is found, the argument immediately following
it is returned (without modification), and the argument and its
value are removed from the command line..
If there is no argument immediately following it, or if the value
is not an integer, SyntaxError is thrown.
namedescrdfltpublic int findArg(java.lang.String name)
name
and returns its index or -1.
The argument is not removed from the command line.
name
public java.lang.String getArgValue(java.lang.String name,
java.lang.String descr)
throws CommandLine.SyntaxError
name
and a following value.
If found, removes the argument and its value from the command line
and returns the value. If name is not found, returns null.
If name is found without a value, a SyntaxError is thrown.
namedescrpublic boolean getHelpArg()
"-h", "-?", "/h", "/?", "-help", "/help".
If one is found, it is removed from the command line and
true is returned. Otherwise false is returned.
| Revision History |
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | CONST | FIELD | CONSTR | METHOD | DETAIL: CONST | FIELD | CONSTR | METHOD | ||||||||
CommandLine.java (PRIVATE SOURCES)