|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcmdline.AbstractHandlerDecorator
jcmdline.HelpCmdLineHandler
A CmdLineHandler Decorator class that implements help options that display verbose help messages.
Options are provided to display a regular help message (which includes the regular usage associated with the command) or a help message that includes the hidden parameters in its usage and, optionally, additional help text specific to the hidden parameters.
The implemented options are BooleanParams whose tags are defined by "HelpCmdLineHandler.help.tag" and "HelpCmdLineHandler.helpHidden.tag" in the strings.properties file (set to "help" and "help!", in English).
Should the user specify the -help option on the command line, the command's
usage, followed by the more verbose help text specified to this Object's
constructor, is printed to stdout, and System.exit(0)
is called.
Should the -help! option be specified the same is done, but hidden parameter information and help is displayed as well.
Sample Usage
The following creates a CmdLineHandler that uses multiple Decorators
to enable the help options supported by this class, the version option
implemented by the VersionCmdLineHandler
class, and the usage
options implemented by the DefaultCmdLineHandler
class:
public static void main(String[] args) { Parameter[] arguments = new Parameter[] { new StringParam("pattern", "the pattern to match", StringParam.REQUIRED), new FileParam("file", "a file to be processed - defaults to stdin", FileParam.IS_FILE & FileParam.IS_READABLE, FileParam.OPTIONAL, FileParam.MULTI_VALUED) }; Parameter[] opts = new Parameter[] { new BooleanParam("ignorecase", "ignore case while matching"), new BooleanParam("listFiles", "list filenames containing pattern") }; String helpText = "This command prints to stdout all lines within " + "the specified files that contain the specified " + "pattern.\n\n" + "Optionally, the matching may be done without " + "regard to case (using the -ignorecase option).\n\n" + "If the -listFiles option is specified, only the " + "names of the files containing the pattern will be " + "listed."; CmdLineHandler cl = new VersionCmdLineHandler("V 5.2", new HelpCmdLineHandler(helpText, "grep", "find lines in files containing a specified pattern", opts, arguments)); cl.parse(args); . .
The help text for a command will be formatted for output such that:
Information on using CmdLineHandlers can be found in the jcmdline User Guide.
CmdLineHandler
,
AbstractHandlerDecorator
Constructor Summary | |
HelpCmdLineHandler(java.lang.String help,
CmdLineHandler handler)
constructor |
|
HelpCmdLineHandler(java.lang.String help,
java.lang.String hiddenHelp,
CmdLineHandler handler)
constructor |
|
HelpCmdLineHandler(java.lang.String help,
java.lang.String cmdName,
java.lang.String cmdDesc,
java.util.Collection options,
java.util.Collection args)
constructor - uses the PosixCmdLineParser to parse the command line |
|
HelpCmdLineHandler(java.lang.String help,
java.lang.String cmdName,
java.lang.String cmdDesc,
Parameter[] options,
Parameter[] args)
constructor - creates a new DefaultCmdLineHandler as its delegate |
|
HelpCmdLineHandler(java.lang.String help,
java.lang.String cmdName,
java.lang.String cmdDesc,
Parameter[] options,
Parameter[] args,
CmdLineParser parser)
constructor - creates a new DefaultCmdLineHandler as its delegate |
|
HelpCmdLineHandler(java.lang.String help,
java.lang.String hiddenHelp,
java.lang.String cmdName,
java.lang.String cmdDesc,
java.util.Collection options,
java.util.Collection args)
constructor - uses the PosixCmdLineParser to parse the command line |
|
HelpCmdLineHandler(java.lang.String help,
java.lang.String hiddenHelp,
java.lang.String cmdName,
java.lang.String cmdDesc,
Parameter[] options,
Parameter[] args)
constructor - creates a new DefaultCmdLineHandler as its delegate |
|
HelpCmdLineHandler(java.lang.String help,
java.lang.String hiddenHelp,
java.lang.String cmdName,
java.lang.String cmdDesc,
Parameter[] options,
Parameter[] args,
CmdLineParser parser)
constructor - creates a new DefaultCmdLineHandler as its delegate |
Method Summary | |
protected boolean |
processParsedOptions(boolean parseOk)
Called following the call to parse() of this class's
contained CmdLineHandler. |
Methods inherited from class jcmdline.AbstractHandlerDecorator |
addArg, addOption, exitUsageError, getArg, getArgs, getCmdDesc, getCmdName, getCustomOptions, getDieOnParseError, getOption, getOptions, getParseError, getParser, getUsage, parse, setArgs, setCmdDesc, setCmdName, setCustomOptions, setDieOnParseError, setOptions, setParseError, setParser |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HelpCmdLineHandler(java.lang.String help, java.lang.String hiddenHelp, CmdLineHandler handler)
help
- the command's help - see Help
Text Formatting.hiddenHelp
- the command's help for hidden Parameters - may
be null or emptyhandler
- the CmdLineHandler to which most functionality
will be delegated
java.lang.IllegalArgumentException
- if help
is null or
empty.public HelpCmdLineHandler(java.lang.String help, CmdLineHandler handler)
help
- the command's help - see Help
Text Formatting.handler
- the CmdLineHandler to which most functionality
will be delegated
java.lang.IllegalArgumentException
- if help
is null or
empty.public HelpCmdLineHandler(java.lang.String help, java.lang.String cmdName, java.lang.String cmdDesc, Parameter[] options, Parameter[] args, CmdLineParser parser)
help
- the command's help - see
Help Text Formatting.cmdName
- the name of the commandcmdDesc
- a short description of the commandoptions
- a collection of Parameter objects, describing the
command's command-line optionsargs
- a collection of Parameter objects, describing the
command's command-line arguments (what is left on
the command line after all options and their
parameters have been processed)parser
- a CmdLineParser to be used to parse the command line
java.lang.IllegalArgumentException
- if any of the
parameters are not correctly specified.DefaultCmdLineHandler
public HelpCmdLineHandler(java.lang.String help, java.lang.String cmdName, java.lang.String cmdDesc, Parameter[] options, Parameter[] args)
help
- the command's help - see
Help Text Formatting.cmdName
- the name of the commandcmdDesc
- a short description of the commandoptions
- a collection of Parameter objects, describing the
command's command-line optionsargs
- a collection of Parameter objects, describing the
command's command-line arguments (what is left on
the command line after all options and their
parameters have been processed)
java.lang.IllegalArgumentException
- if any of the
parameters are not correctly specified.DefaultCmdLineHandler
public HelpCmdLineHandler(java.lang.String help, java.lang.String cmdName, java.lang.String cmdDesc, java.util.Collection options, java.util.Collection args)
help
- the command's help - see
Help Text Formatting.cmdName
- the name of the command creating this
DefaultCmdLineHandlercmdDesc
- a short description of the command's purposeoptions
- a collection of Parameter objects, describing the
command's command-line optionsargs
- a collection of Parameter objects, describing the
command's command-line arguments (what is left on
the command line after all options and their
parameters have been processed)
java.lang.IllegalArgumentException
- if any of the
parameters are not correctly specified.setCmdName()
,
setCmdDesc()
,
setOptions()
,
PosixCmdLineParser
public HelpCmdLineHandler(java.lang.String help, java.lang.String hiddenHelp, java.lang.String cmdName, java.lang.String cmdDesc, Parameter[] options, Parameter[] args, CmdLineParser parser)
help
- the command's help - see
Help Text Formatting.hiddenHelp
- the command's help for hidden Parameters - may
be null or emptycmdName
- the name of the commandcmdDesc
- a short description of the commandoptions
- a collection of Parameter objects, describing the
command's command-line optionsargs
- a collection of Parameter objects, describing the
command's command-line arguments (what is left on
the command line after all options and their
parameters have been processed)parser
- a CmdLineParser to be used to parse the command line
java.lang.IllegalArgumentException
- if any of the
parameters are not correctly specified.DefaultCmdLineHandler
public HelpCmdLineHandler(java.lang.String help, java.lang.String hiddenHelp, java.lang.String cmdName, java.lang.String cmdDesc, Parameter[] options, Parameter[] args)
help
- the command's help - see
Help Text Formatting.hiddenHelp
- the command's help for hidden Parameters - may
be null or emptycmdName
- the name of the commandcmdDesc
- a short description of the commandoptions
- a collection of Parameter objects, describing the
command's command-line optionsargs
- a collection of Parameter objects, describing the
command's command-line arguments (what is left on
the command line after all options and their
parameters have been processed)
java.lang.IllegalArgumentException
- if any of the
parameters are not correctly specified.DefaultCmdLineHandler
public HelpCmdLineHandler(java.lang.String help, java.lang.String hiddenHelp, java.lang.String cmdName, java.lang.String cmdDesc, java.util.Collection options, java.util.Collection args)
help
- the command's help - see
Help Text Formatting.hiddenHelp
- the command's help for hidden Parameters - may
be null or emptycmdName
- the name of the command creating this
DefaultCmdLineHandlercmdDesc
- a short description of the command's purposeoptions
- a collection of Parameter objects, describing the
command's command-line optionsargs
- a collection of Parameter objects, describing the
command's command-line arguments (what is left on
the command line after all options and their
parameters have been processed)
java.lang.IllegalArgumentException
- if any of the
parameters are not correctly specified.setCmdName()
,
setCmdDesc()
,
setOptions()
,
PosixCmdLineParser
Method Detail |
protected boolean processParsedOptions(boolean parseOk)
parse()
of this class's
contained CmdLineHandler. This method checks for its option whether
parseStatus
is true or not.
processParsedOptions
in class AbstractHandlerDecorator
parseOk
- the results of the parse() call. Note that
if dieOnParseError
is set, or some
other AbstractHandlerDecorator exits first, this
method may never be called.
System.exit(0)
, rather
than returning, if its option is set.
Otherwise, parseStatus
is returned.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |