public class Options
extends java.lang.Object
Stores a set of options and provides methods to parse command line arguments
and convert them into option instances based on the options in this object.
Like Option
, Options
stores everything a set of options
could be, and Options.Instance
stores the set of option instances
from an actual parse of a command line. The Options.Instance
object's
behaviour is determined by the constraints placed by it's related
Options
object and the Option
s it contains. See
Options.Instance.parse(java.lang.String[])
for a complete description on how arguments
are parsed into options. If an object has a long name, it must be different
to the long names of all other options in this object. The same is true for
short names.
Modifier and Type | Class and Description |
---|---|
class |
Options.Instance
An instance of an
Options object contains all options found in
arguments on a command line. |
Constructor and Description |
---|
Options() |
Modifier and Type | Method and Description |
---|---|
Options |
addOption(Option opt)
Adds an option to this object
|
Option |
getOption(java.lang.String argName)
Returns the specified option, or
null if this object does not
contain an option by this name. |
java.util.Collection<Option> |
getOptions()
Returns an unmodifiable collection of all the options in this object.
|
boolean |
hasOption(java.lang.String argName)
Tests to see if the specified option is present.
|
Options.Instance |
newInstance()
Returns a new instance of this options set that can store option instances
from a parsed command line
|
Options.Instance |
newInstance(java.lang.String[] args)
Returns a new instance of this options set containing the option instances
defined in the arguments passed in.
|
java.lang.String |
toString() |
public Options addOption(Option opt) throws java.lang.IllegalArgumentException
opt
- The option to addOptions
objectjava.lang.IllegalArgumentException
- If this objct already contains an option with the same long or
short name as opt
public java.util.Collection<Option> getOptions()
public Option getOption(java.lang.String argName)
null
if this object does not
contain an option by this name. The name is expected to have one or two
hyphens at the beginning. These will be stripped. This method will work if
the hyphens are not present so long as the name itself doesn't start with
hyphens. In that case, the hyphens will be erroneously stripped.argName
- The name of the argument to return. The name is expected to start
with hyphenspublic boolean hasOption(java.lang.String argName)
argName
- The name of the argument to return. The name is expected to start
with hyphenspublic Options.Instance newInstance()
public Options.Instance newInstance(java.lang.String[] args)
args
- the command line arguments to parsepublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()