org.apache.commons.cli

Class Options

public class Options extends Object

Main entry-point into the library.

Options represents a collection of Option objects, which describe the possible options for a command-line.

It may flexibly parse long and short options, with or without values. Additionally, it may parse only a portion of a commandline, allowing for flexible multi-stage parsing.

Version: $Revision: 1.5 $

Author: bob mcwhirter (bob @ werken.com) James Strachan

See Also:

Field Summary
MaplongOpts
a map of the options with the long key
MapoptionGroups
a map of the option groups
ListrequiredOpts
a map of the required options
MapshortOpts
a map of the options with the character key
Constructor Summary
Options()

Construct a new Options descriptor

Method Summary
OptionsaddOption(String opt, boolean hasArg, String description)

Add an option that only contains a short-name

It may be specified as requiring an argument.

OptionsaddOption(String opt, String longOpt, boolean hasArg, String description)

Add an option that contains a short-name and a long-name

It may be specified as requiring an argument.

OptionsaddOption(Option opt)

Adds an option instance

OptionsaddOptionGroup(OptionGroup group)

Add the specified option group.

OptiongetOption(String opt)

Retrieve the named Option

OptionGroupgetOptionGroup(Option opt)

Returns the OptionGroup the opt belongs to.

CollectiongetOptions()

Retrieve a read-only list of options in this set

ListgetRequiredOptions()

Returns the required options as a java.util.Collection.

booleanhasOption(String opt)

Returns whether the named Option is a member of this Options

ListhelpOptions()

Returns the Options for use by the HelpFormatter.

StringtoString()

Dump state, suitable for debugging.

Field Detail

longOpts

private Map longOpts
a map of the options with the long key

optionGroups

private Map optionGroups
a map of the option groups

requiredOpts

private List requiredOpts
a map of the required options

shortOpts

private Map shortOpts
a map of the options with the character key

Constructor Detail

Options

public Options()

Construct a new Options descriptor

Method Detail

addOption

public Options addOption(String opt, boolean hasArg, String description)

Add an option that only contains a short-name

It may be specified as requiring an argument.

Parameters: opt Short single-character name of the option. hasArg flag signally if an argument is required after this option description Self-documenting description

Returns: the resulting Options instance

addOption

public Options addOption(String opt, String longOpt, boolean hasArg, String description)

Add an option that contains a short-name and a long-name

It may be specified as requiring an argument.

Parameters: opt Short single-character name of the option. longOpt Long multi-character name of the option. hasArg flag signally if an argument is required after this option description Self-documenting description

Returns: the resulting Options instance

addOption

public Options addOption(Option opt)

Adds an option instance

Parameters: opt the option that is to be added

Returns: the resulting Options instance

addOptionGroup

public Options addOptionGroup(OptionGroup group)

Add the specified option group.

Parameters: group the OptionGroup that is to be added

Returns: the resulting Options instance

getOption

public Option getOption(String opt)

Retrieve the named Option

Parameters: opt short or long name of the Option

Returns: the option represented by opt

getOptionGroup

public OptionGroup getOptionGroup(Option opt)

Returns the OptionGroup the opt belongs to.

Parameters: opt the option whose OptionGroup is being queried.

Returns: the OptionGroup if opt is part of an OptionGroup, otherwise return null

getOptions

public Collection getOptions()

Retrieve a read-only list of options in this set

Returns: read-only Collection of Option objects in this descriptor

getRequiredOptions

public List getRequiredOptions()

Returns the required options as a java.util.Collection.

Returns: Collection of required options

hasOption

public boolean hasOption(String opt)

Returns whether the named Option is a member of this Options

Parameters: opt short or long name of the Option

Returns: true if the named Option is a member of this Options

helpOptions

List helpOptions()

Returns the Options for use by the HelpFormatter.

Returns: the List of Options

toString

public String toString()

Dump state, suitable for debugging.

Returns: Stringified form of this object