| Parses command line arguments according to GNU's conventions.
This parser supports both short options and long options.
There are two ways to tell the parser what options to recognize:
- A "domain-specific language"-style API for specifying options, available since
version 2. Sentences in this domain-specific language begin with a call to
OptionParser.accepts(String) accepts ; methods on the ensuing chain of objects describe
whether the option passed to
OptionParser.accepts(String) accepts can take an argument,
whether the argument is required or optional, and to what type arguments of the
option should be converted.
- Since version 1, a more concise way of specifying short options to recognize has
been to use the special
. Arguments
of options specified in this manner will be of type
String . Here are the
rules for the format of the specification strings this constructor accepts:
- Any letter or digit is treated as an option character.
- If an option character is followed by a single colon (
":" ),
then the option requires an argument.
- If an option character is followed by two colons (
"::" ), then
the option accepts an optional argument.
- Otherwise, the option character accepts no argument.
- If the option specification string begins with a plus sign
(
"+" ), the parser will behave "POSIX-ly correct".
- If the option specification string contains the sequence
"W;"
(capital W followed by a semicolon), the parser will recognize the alternative
form of long options.
By default, as with GNU getopt() , the parser allows intermixing of
options and non-options. If, however, the parser has been created to be "POSIX-ly
correct", then the first argument that does not look lexically like an option, and
is not a required argument of a preceding option, signals the end of options.
You can still bind optional arguments to their options using the abutting (for short
options) or = syntax.
Unlike GNU getopt() , this parser does not honor the
environment variable POSIXLY_CORRECT . "POSIX-ly correct" parsers are
configured by either:
- using the method
OptionParser.setPosixlyCorrect(boolean) , or
- using the
with an argument whose
first character is a plus sign (
"+" )
since: 1.0 author: Paul Holser version: $Id: OptionParser.java,v 1.42 2007/04/21 22:24:58 pholser Exp $ See Also: The GNU C Library |