|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.townleyenterprises.command.CommandOption
This class provides support for defining command-line arguments.
Constructor Summary | |
CommandOption(java.lang.String longName,
char shortName,
boolean hasArg,
java.lang.String argHelp,
java.lang.String argDesc)
The class is fully initialized by the constructor and each argument is immutable once it has been set. |
|
CommandOption(java.lang.String longName,
char shortName,
boolean hasArg,
java.lang.String argHelp,
java.lang.String argDesc,
boolean show,
java.lang.String def)
This version of the constructor allows specifying if the argument is to be shown to the user and if the argument has a default value if it is not specified on the command line. |
|
CommandOption(java.lang.String longName,
char shortName,
boolean hasArg,
java.lang.String argHelp,
java.lang.String argDesc,
java.lang.String def)
This version of the constructor allows specifying if the argument has a default value. |
Method Summary | |
void |
execute()
This method is used to allow the class to implement the GoF Command pattern fully. |
java.lang.String |
getArg()
This method is used to retrieve the argument (if any) which was given to the option. |
java.lang.String |
getArgumentDefault()
|
java.lang.Object |
getArgValue()
This method is used to provide the argument parsed as the appropriate type. |
java.lang.String |
getDescription()
|
boolean |
getExpectsArgument()
|
java.lang.String |
getHelp()
|
java.lang.String |
getLongName()
|
boolean |
getMatched()
Indicates if this option has been matched by the command parser or not. |
java.lang.String |
getName()
This method is used to return some sort of normailzed name for the option. |
java.lang.Character |
getShortName()
|
boolean |
getShowArgInHelp()
|
int |
hashCode()
|
void |
optionMatched(java.lang.String arg)
This method is called by the command parser to indicate that the option has been matched. |
static java.lang.String[] |
parseOption(java.lang.String str)
This method is used to break up a key=val
string into a 2 element array of arr[0] = key
and arr[1] = val . |
static java.util.Map |
parseOptions(java.util.List list)
This method is used to parse a list options of the form key=val into a map which is easier to
manipulate. |
void |
reset()
This method is used to support multiple parses by a CommandParser instance using different sets of arguments. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CommandOption(java.lang.String longName, char shortName, boolean hasArg, java.lang.String argHelp, java.lang.String argDesc)
longName
- the long name to be checkedshortName
- the short, single character namehasArg
- true if this option expects an argument;
false if it is a switchargHelp
- the help string for the argumentargDesc
- the long description of what the argument
doespublic CommandOption(java.lang.String longName, char shortName, boolean hasArg, java.lang.String argHelp, java.lang.String argDesc, boolean show, java.lang.String def)
longName
- the long name to be checkedshortName
- the short, single character namehasArg
- true if this option expects an argument;
false if it is a switchargHelp
- the help string for the argumentargDesc
- the long description of what the argument
doesshow
- true if should be shown in autohelpdef
- the default value of the argument if it is not
specified.public CommandOption(java.lang.String longName, char shortName, boolean hasArg, java.lang.String argHelp, java.lang.String argDesc, java.lang.String def)
longName
- the long name to be checkedshortName
- the short, single character namehasArg
- true if this option expects an argument;
false if it is a switchargHelp
- the help string for the argumentargDesc
- the long description of what the argument
doesdef
- the default value of the argument if it is not
specified.Method Detail |
public static java.lang.String[] parseOption(java.lang.String str)
key=val
string into a 2 element array of arr[0] = key
and arr[1] = val
.
str
- the string to process
public static java.util.Map parseOptions(java.util.List list)
key=val
into a map which is easier to
manipulate.
list
- the list of options
public java.lang.String getLongName()
public java.lang.Character getShortName()
public boolean getExpectsArgument()
public java.lang.String getHelp()
public java.lang.String getDescription()
public boolean getShowArgInHelp()
public java.lang.String getArgumentDefault()
public int hashCode()
public java.lang.String getArg()
public boolean getMatched()
public void optionMatched(java.lang.String arg)
This method may be overridden by derived classes to provide
object-oriented command-line argument handling. The
default implementation simply sets the value returned by
getMatched()
to true
and stores the
argument.
arg
- the argument (if expected)public void reset()
public java.lang.Object getArgValue()
public void execute() throws java.lang.Exception
java.lang.Exception
- if something fails.public java.lang.String getName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |