Package org.apache.commons.cli
Class Options
java.lang.Object
org.apache.commons.cli.Options
- All Implemented Interfaces:
Serializable
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:
- $Id: Options.java 1754332 2016-07-27 18:47:57Z britter $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptiona map of the options with the long keyprivate final Map<String,
OptionGroup> a map of the option groupsa map of the required optionsprivate static final long
The serial version UID.a map of the options with the character key -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd an option that only contains a short-name.Add an option that only contains a short name.Add an option that contains a short-name and a long-name.Adds an option instanceaddOptionGroup
(OptionGroup group) Add the specified option group.addRequiredOption
(String opt, String longOpt, boolean hasArg, String description) Add an option that contains a short-name and a long-name.(package private) Option
getLongOption
(String opt) Retrieve theOption
matching the long name specified.getMatchingOptions
(String opt) Returns the options with a long name starting with the name specified.Retrieve theOption
matching the long or short name specified.getOptionGroup
(Option opt) Returns the OptionGroup theopt
belongs to.(package private) Collection<OptionGroup>
Lists the OptionGroups that are members of this Options instance.Retrieve a read-only list of options in this setReturns the required options.boolean
hasLongOption
(String opt) boolean
boolean
hasShortOption
(String opt) Returns the Options for use by the HelpFormatter.toString()
Dump state, suitable for debugging.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDThe serial version UID.- See Also:
-
shortOpts
a map of the options with the character key -
longOpts
a map of the options with the long key -
requiredOpts
a map of the required options -
optionGroups
a map of the option groups
-
-
Constructor Details
-
Options
public Options()
-
-
Method Details
-
addOptionGroup
Add the specified option group.- Parameters:
group
- the OptionGroup that is to be added- Returns:
- the resulting Options instance
-
getOptionGroups
Collection<OptionGroup> getOptionGroups()Lists the OptionGroups that are members of this Options instance.- Returns:
- a Collection of OptionGroup instances.
-
addOption
Add an option that only contains a short name.The option does not take an argument.
- Parameters:
opt
- Short single-character name of the option.description
- Self-documenting description- Returns:
- the resulting Options instance
- Since:
- 1.3
-
addOption
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 optiondescription
- Self-documenting description- Returns:
- the resulting Options instance
-
addOption
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 optiondescription
- Self-documenting description- Returns:
- the resulting Options instance
-
addRequiredOption
Add an option that contains a short-name and a long-name.The added option is set as required. It may be specified as requiring an argument. This method is a shortcut for:
Options option = new Option(opt, longOpt, hasArg, description); option.setRequired(true); options.add(option);
- 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 optiondescription
- Self-documenting description- Returns:
- the resulting Options instance
- Since:
- 1.4
-
addOption
Adds an option instance- Parameters:
opt
- the option that is to be added- Returns:
- the resulting Options instance
-
getOptions
Retrieve a read-only list of options in this set- Returns:
- read-only Collection of
Option
objects in this descriptor
-
helpOptions
Returns the Options for use by the HelpFormatter.- Returns:
- the List of Options
-
getRequiredOptions
Returns the required options.- Returns:
- read-only List of required options
-
getOption
Retrieve theOption
matching the long or short name specified.The leading hyphens in the name are ignored (up to 2).
- Parameters:
opt
- short or long name of theOption
- Returns:
- the option represented by opt
-
getLongOption
Retrieve theOption
matching the long name specified. The leading hyphens in the name are ignored (up to 2).- Parameters:
opt
- long name of theOption
- Returns:
- the option represented by opt
-
getMatchingOptions
Returns the options with a long name starting with the name specified.- Parameters:
opt
- the partial name of the option- Returns:
- the options matching the partial name specified, or an empty list if none matches
- Since:
- 1.3
-
hasOption
-
hasLongOption
-
hasShortOption
-
getOptionGroup
Returns the OptionGroup theopt
belongs to.- Parameters:
opt
- the option whose OptionGroup is being queried.- Returns:
- the OptionGroup if
opt
is part of an OptionGroup, otherwise return null
-
toString
Dump state, suitable for debugging.
-