|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjcmdline.PosixCmdLineParser
public class PosixCmdLineParser
Used to parse the parameters associated with an executable's command line.
The following semantics are used throughout the documentation for this class. A command line parameter refers to either a command line option, or a command line argument.
A command line option is preceded by either a '-', or a '--', and may, optionally, have an associated value separated from the option "tag" by a space or an '='. Command line options end with the first parameter (that has not already been parsed as an option or option value) that does not start with a '-' or a '--', or when a '--' appears by itself as a parameter. A '--' must be specified alone to signal the end of options when the first command line argument starts with a '-'.
Command line arguments are what are left on the command line after all options have been processed.
This class is used as in the following example of a 'cat' facsimile in java:
Command Line Parsing
The parse() method parses option tags in
a case insensitive manner. It will accept truncated option tags as long as
the tag remains un-ambiguous, execpt for hidden options. The tag for hidden
options must be fully specified. An option's value may be separated from its'
tag by a space or an '='. A BooleanParam may be specified either without a
value (in which case it is set to true), or with an '=' followed
by its value. If a BooleanParam is specified more than once, the final
specification takes precedence.
The following command lines are all equivalent:
java Concat -delete -out myoutfile infile1 infile2 java Concat -d -o myoutfile infile1 infile2 java Concat -delete=true -o myoutfile infile1 infile2 java Concat -d=true -o=myoutfile infile1 infile2 java Concat -Delete -OUT myoutfile infile1 infile2Any problem found while
parse() processes the command line will
cause a CmdLineException to be thrown.
Information on using CmdLineParsers can be found in the jcmdline User Guide.
Parameter| Constructor Summary | |
|---|---|
PosixCmdLineParser()
constructor |
|
| Method Summary | |
|---|---|
UsageFormatter |
getUsageFormatter()
Gets a usage formatter suitable for this CmdLineParser's format. |
void |
parse(java.lang.String[] clargs,
java.util.Map<java.lang.String,Parameter<?>> opts,
java.util.List<Parameter<?>> args)
Parse the specified command line arguments. |
void |
setUsageFormatter(UsageFormatter usageFormatter)
Sets a usage formatter suitable for this CmdLineParser's format. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PosixCmdLineParser()
| Method Detail |
|---|
public UsageFormatter getUsageFormatter()
getUsageFormatter in interface CmdLineParsersetUsageFormatter()
public void parse(java.lang.String[] clargs,
java.util.Map<java.lang.String,Parameter<?>> opts,
java.util.List<Parameter<?>> args)
throws CmdLineException
This method will exit, rather than returning, if one of the following conditions is met:
parse in interface CmdLineParserclargs - command line arguments passed to the main() method of
CmdLineParser's creating class.opts - the options this command supportsargs - the arguments this command supports
CmdLineException - in case of any parse error.public void setUsageFormatter(UsageFormatter usageFormatter)
setUsageFormatter in interface CmdLineParserusageFormatter - a usage formatter suitable for this CmdLineParser's formatgetUsageFormatter()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||