jargs.gnu

Class CmdLineParser

public class CmdLineParser extends Object

Largely GNU-compatible command-line options parser. Has short (-v) and long-form (--verbose) option support, and also allows options with associated values (-d 2, --debug 2, --debug=2). Option processing can be explicitly terminated by the argument '--'.

Version: $Revision: 1.10 $

Author: Steve Purcell

See Also: OptionTest

Nested Class Summary
static classCmdLineParser.IllegalOptionValueException
Thrown when an illegal or missing value is given by the user for an option that takes a value.
static classCmdLineParser.NotFlagException
Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one or more requires a value.
abstract static classCmdLineParser.Option
Representation of a command-line option
abstract static classCmdLineParser.OptionException
Base class for exceptions that may be thrown when options are parsed
static classCmdLineParser.UnknownOptionException
Thrown when the parsed command-line contains an option that is not recognised.
static classCmdLineParser.UnknownSuboptionException
Thrown when the parsed commandline contains multiple concatenated short options, such as -abcd, where one is unknown.
Method Summary
CmdLineParser.OptionaddBooleanOption(char shortForm, String longForm)
Convenience method for adding a boolean option.
CmdLineParser.OptionaddBooleanOption(String longForm)
Convenience method for adding a boolean option.
CmdLineParser.OptionaddDoubleOption(char shortForm, String longForm)
Convenience method for adding a double option.
CmdLineParser.OptionaddDoubleOption(String longForm)
Convenience method for adding a double option.
CmdLineParser.OptionaddIntegerOption(char shortForm, String longForm)
Convenience method for adding an integer option.
CmdLineParser.OptionaddIntegerOption(String longForm)
Convenience method for adding an integer option.
CmdLineParser.OptionaddLongOption(char shortForm, String longForm)
Convenience method for adding a long integer option.
CmdLineParser.OptionaddLongOption(String longForm)
Convenience method for adding a long integer option.
CmdLineParser.OptionaddOption(CmdLineParser.Option opt)
Add the specified Option to the list of accepted options
CmdLineParser.OptionaddStringOption(char shortForm, String longForm)
Convenience method for adding a string option.
CmdLineParser.OptionaddStringOption(String longForm)
Convenience method for adding a string option.
ObjectgetOptionValue(CmdLineParser.Option o)
ObjectgetOptionValue(CmdLineParser.Option o, Object def)
VectorgetOptionValues(CmdLineParser.Option option)
String[]getRemainingArgs()
voidparse(String[] argv)
Extract the options and non-option arguments from the given list of command-line arguments.
voidparse(String[] argv, Locale locale)
Extract the options and non-option arguments from the given list of command-line arguments.

Method Detail

addBooleanOption

public final CmdLineParser.Option addBooleanOption(char shortForm, String longForm)
Convenience method for adding a boolean option.

Returns: the new Option

addBooleanOption

public final CmdLineParser.Option addBooleanOption(String longForm)
Convenience method for adding a boolean option.

Returns: the new Option

addDoubleOption

public final CmdLineParser.Option addDoubleOption(char shortForm, String longForm)
Convenience method for adding a double option.

Returns: the new Option

addDoubleOption

public final CmdLineParser.Option addDoubleOption(String longForm)
Convenience method for adding a double option.

Returns: the new Option

addIntegerOption

public final CmdLineParser.Option addIntegerOption(char shortForm, String longForm)
Convenience method for adding an integer option.

Returns: the new Option

addIntegerOption

public final CmdLineParser.Option addIntegerOption(String longForm)
Convenience method for adding an integer option.

Returns: the new Option

addLongOption

public final CmdLineParser.Option addLongOption(char shortForm, String longForm)
Convenience method for adding a long integer option.

Returns: the new Option

addLongOption

public final CmdLineParser.Option addLongOption(String longForm)
Convenience method for adding a long integer option.

Returns: the new Option

addOption

public final CmdLineParser.Option addOption(CmdLineParser.Option opt)
Add the specified Option to the list of accepted options

addStringOption

public final CmdLineParser.Option addStringOption(char shortForm, String longForm)
Convenience method for adding a string option.

Returns: the new Option

addStringOption

public final CmdLineParser.Option addStringOption(String longForm)
Convenience method for adding a string option.

Returns: the new Option

getOptionValue

public final Object getOptionValue(CmdLineParser.Option o)
Equivalent to getOptionValue(o, null).

getOptionValue

public final Object getOptionValue(CmdLineParser.Option o, Object def)

Returns: the parsed value of the given Option, or null if the option was not set

getOptionValues

public final Vector getOptionValues(CmdLineParser.Option option)

Returns: A Vector giving the parsed values of all the occurrences of the given Option, or an empty Vector if the option was not set.

getRemainingArgs

public final String[] getRemainingArgs()

Returns: the non-option arguments

parse

public final void parse(String[] argv)
Extract the options and non-option arguments from the given list of command-line arguments. The default locale is used for parsing options whose values might be locale-specific.

parse

public final void parse(String[] argv, Locale locale)
Extract the options and non-option arguments from the given list of command-line arguments. The specified locale is used for parsing options whose values might be locale-specific.
Copyright © 2001-2003 Steve Purcell. Copyright © 2002 Vidar Holen. Copyright © 2002 Michal Ceresna. Copyright © 2005 Ewan Mellor. Released under the terms of the BSD licence.