|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface CmdLineHandler
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 |
---|
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()
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()
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()
.void setParser(CmdLineParser parser)
parser
- the parser to be used to parse the command linegetParser()
CmdLineParser getParser()
setParser()
void setArgs(Parameter[] args)
args
- A Collection of Parameter
objects. This may
be null if the command accepts no command line
arguments.void addArg(Parameter arg)
arg
- the new command line argument
java.lang.IllegalArgumentException
- if arg
is null.java.util.List getArgs()
Parameter getArg(java.lang.String tag)
tag
tag
- identifies the argument to be returned
tag
.
If no matching argument is found, null is returned.void setOptions(Parameter[] options)
options
- A Collection of Parameter
objects. This may
be null if the command accepts no command line
options.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.java.util.Collection getOptions()
Parameter getOption(java.lang.String tag)
tag
tag
- identifies the option to be returned
tag
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.java.lang.String getCmdDesc()
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 lengthjava.lang.String getCmdName()
java.lang.String getUsage(boolean hidden)
hidden
- indicates whether hidden options are to be included
in the usage.
void setParseError(java.lang.String parseError)
parseError
- the error message from the last call to parse()getParseError()
java.lang.String getParseError()
setParseError()
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 |