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