|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface that describes the API for a command line handler. A command line handler is an object that is passed information concerning the required structure of command's command line and then can be used to parse the command line, taking action as configured.
Information on using CmdLineHandlers can be found in the jcmdline User Guide.
Parameter
,
CmdLineParser
,
UsageFormatter
Method Summary | |
void |
addArg(Parameter arg)
Adds a command line arguement. |
void |
addOption(Parameter opt)
Adds a command line option. |
void |
exitUsageError(java.lang.String errMsg)
Prints the usage, followed by the specified error message, to stderr and exits the program with exit status = 1. |
Parameter |
getArg(java.lang.String tag)
gets the argument specified by tag |
java.util.List |
getArgs()
gets the value of the arguments (what is left on the command line after all options, and their parameters, have been processed) associated with the command |
java.lang.String |
getCmdDesc()
gets a description of the command's purpose |
java.lang.String |
getCmdName()
gets the value of the command name associated with this CmdLineHandler |
boolean |
getDieOnParseError()
Gets a flag indicating that the program should exit in the case of a parse error (after displaying the usage and an error message). |
Parameter |
getOption(java.lang.String tag)
gets the option specified by tag |
java.util.Collection |
getOptions()
gets the value of the options associated with the command |
java.lang.String |
getParseError()
Gets the error message from the last call to parse(). |
CmdLineParser |
getParser()
Gets the parser to be used to parse the command line. |
java.lang.String |
getUsage(boolean hidden)
Gets the usage statement associated with the command. |
boolean |
parse(java.lang.String[] clargs)
parse the specified command line arguments |
void |
setArgs(Parameter[] args)
sets the value of the arguments (what is left on the command line after all options, and their parameters, have been processed) associated with the command |
void |
setCmdDesc(java.lang.String cmdDesc)
sets a description of the command's purpose |
void |
setCmdName(java.lang.String cmdName)
sets the value of the command name associated with this CmdLineHandler |
void |
setDieOnParseError(boolean val)
Sets a flag indicating that the program should exit in the case of a parse error (after displaying the usage and an error message) - defaults to true . |
void |
setOptions(Parameter[] options)
Sets the value of the options associated with the command |
void |
setParseError(java.lang.String parseError)
Sets the error message from the last call to parse(). |
void |
setParser(CmdLineParser parser)
Sets the parser to be used to parse the command line. |
Method Detail |
public void setDieOnParseError(boolean val)
true
.
val
- true
(the default) if the
parse
method should call System.exit() in
case of a parse error, false
if
parse()
should return to the user
for error processing.parse()
public boolean getDieOnParseError()
true
(the default) if the
parse
method should call System.exit() in
case of a parse error, false
if
parse()
should return to the user
for error processing.parse()
public boolean parse(java.lang.String[] clargs)
clargs
- command line arguments passed to the main() method
of CmdLineHandler's creating class.
dieOnParseError
is set to false
,
this method will return true if there are no parse errors. If
there are parse errors, false
is returned and
an appropriate error message may be obtained by calling
getParseError()
.public void setParser(CmdLineParser parser)
parser
- the parser to be used to parse the command linegetParser()
public CmdLineParser getParser()
setParser()
public void setArgs(Parameter[] args)
args
- A Collection of Parameter
objects. This may
be null if the command accepts no command line
arguments.public void addArg(Parameter arg)
arg
- the new command line argument
java.lang.IllegalArgumentException
- if arg
is null.public java.util.List getArgs()
public Parameter getArg(java.lang.String tag)
tag
tag
- identifies the argument to be returned
tag
.
If no matching argument is found, null is returned.public void setOptions(Parameter[] options)
options
- A Collection of Parameter
objects. This may
be null if the command accepts no command line
options.public void addOption(Parameter opt)
opt
- the new command line option
java.lang.IllegalArgumentException
- if the tag associated with
opt
has already been defined for an
option.public java.util.Collection getOptions()
public Parameter getOption(java.lang.String tag)
tag
tag
- identifies the option to be returned
tag
public void setCmdDesc(java.lang.String cmdDesc)
cmdDesc
- a short description of the command's purpose
java.lang.IllegalArgumentException
- if cmdDesc
is null or of 0 length.public java.lang.String getCmdDesc()
public void setCmdName(java.lang.String cmdName)
cmdName
- the name of the command associated with this
CmdLineHandler
java.lang.IllegalArgumentException
- if cmdName is null,
or of 0 lengthpublic java.lang.String getCmdName()
public java.lang.String getUsage(boolean hidden)
hidden
- indicates whether hidden options are to be included
in the usage.
public void setParseError(java.lang.String parseError)
parseError
- the error message from the last call to parse()getParseError()
public java.lang.String getParseError()
setParseError()
public void exitUsageError(java.lang.String errMsg)
errMsg
- the error message
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |