public class Options extends Object implements 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.
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 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.
|
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 |
getOptions()
Retrieve a read-only list of options in this set
|
List |
getRequiredOptions()
Returns the required options.
|
boolean |
hasOption(String opt)
|
String |
toString()
Dump state, suitable for debugging.
|
public Options addOptionGroup(OptionGroup group)
group
- the OptionGroup that is to be addedpublic 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 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 boolean hasOption(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.