public class Options extends Object implements Serializable
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.
CommandLine
,
Serialized FormConstructor and Description |
---|
Options() |
Modifier and Type | Method and Description |
---|---|
Options |
addOption(Option opt)
Adds an option instance
|
Options |
addOption(String opt,
boolean hasArg,
String description)
Add an option that only contains a short-name.
|
Options |
addOption(String opt,
String description)
Add an option that only contains a short name.
|
Options |
addOption(String opt,
String longOpt,
boolean hasArg,
String description)
Add an option that contains a short-name and a long-name.
|
Options |
addOptionGroup(OptionGroup group)
Add the specified option group.
|
List<String> |
getMatchingOptions(String opt)
Returns the options with a long name starting with the name specified.
|
Option |
getOption(String opt)
Retrieve the
Option matching the long or short name specified. |
OptionGroup |
getOptionGroup(Option opt)
Returns the OptionGroup the
opt belongs to. |
Collection<Option> |
getOptions()
Retrieve a read-only list of options in this set
|
List |
getRequiredOptions()
Returns the required options.
|
boolean |
hasLongOption(String opt)
|
boolean |
hasOption(String opt)
|
boolean |
hasShortOption(String opt)
|
String |
toString()
Dump state, suitable for debugging.
|
public Options()
public Options addOptionGroup(OptionGroup group)
group
- the OptionGroup that is to be addedpublic Options addOption(String opt, String description)
opt
- Short single-character name of the option.description
- Self-documenting descriptionpublic Options addOption(String opt, boolean hasArg, String description)
opt
- Short single-character name of the option.hasArg
- flag signally if an argument is required after this optiondescription
- Self-documenting descriptionpublic Options addOption(String opt, String longOpt, boolean hasArg, String description)
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 descriptionpublic Options addOption(Option opt)
opt
- the option that is to be addedpublic Collection<Option> getOptions()
Option
objects in this descriptorpublic List getRequiredOptions()
public Option getOption(String opt)
Option
matching the long or short name specified.
The leading hyphens in the name are ignored (up to 2).opt
- short or long name of the Option
public List<String> getMatchingOptions(String opt)
opt
- the partial name of the optionpublic boolean hasLongOption(String opt)
public boolean hasShortOption(String opt)
public OptionGroup getOptionGroup(Option opt)
opt
belongs to.opt
- the option whose OptionGroup is being queried.opt
is part
of an OptionGroup, otherwise return nullCopyright © 2002–2015 The Apache Software Foundation. All rights reserved.