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 {@link VersionCmdLineHandler} class, and the usage options implemented by the {@link 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. @author Lynne Lawrence @version 2007-Dec-04 modified by Andrea Vacondio, added -license param @see CmdLineHandler @see AbstractHandlerDecorator
|
|
|
|
|
|