public class Option extends Object
| Modifier and Type | Field and Description |
|---|---|
protected String |
argName
the option name used in usage message.
|
protected Set<String> |
choices
if the option value has to be in a definited set, this field represents the set of values.
|
static String |
DEFAULT_ARG_NAME
Default name in the usage message.
|
protected String |
defaultValue
the option default value.
|
protected String |
description
The option description.
|
protected boolean |
flag
whether or not the option is a flag.
|
protected boolean |
help
whether or not the option is a "help" option.
|
protected boolean |
hidden
whether or not the option is hidden.
|
protected String |
longName
the option long name.
|
protected boolean |
multiValued
whether or not the option can recevie multiple values.
|
static String |
NO_NAME
The default long name / short name of the option.
|
protected boolean |
required
whether or not the option is required.
|
protected String |
shortName
the option short name.
|
protected boolean |
singleValued
whether or not the option receives a single value.
|
| Constructor and Description |
|---|
Option()
Creates a new empty instance of
Option. |
Option(JsonObject json)
Creates a new instance of
Option from the given JsonObject |
Option(Option other)
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptValue() |
Option |
addChoice(String choice)
Adds a choice to the list of values accepted by this option.
|
void |
ensureValidity()
Checks whether or not the option is valid.
|
String |
getArgName() |
Set<String> |
getChoices() |
String |
getDefaultValue() |
String |
getDescription() |
String |
getLongName() |
String |
getName() |
String |
getShortName() |
boolean |
isFlag() |
boolean |
isHelp()
Checks whether or not this option is a "Help" option.
|
boolean |
isHidden() |
boolean |
isMultiValued() |
boolean |
isRequired() |
boolean |
isSingleValued() |
Option |
setArgName(String argName)
Sets te arg name for this option.
|
Option |
setChoices(Set<String> choices)
Sets the list of values accepted by this option.
|
Option |
setDefaultValue(String defaultValue)
Sets the default value of this option
|
Option |
setDescription(String description)
Sets te description of this option.
|
Option |
setFlag(boolean flag)
Configures the current
Option to be a flag. |
Option |
setHelp(boolean help)
Sets whether or not this option is a "help" option
|
Option |
setHidden(boolean hidden)
Sets whether or not this option should be hidden
|
Option |
setLongName(String longName)
Sets the long name of this option.
|
Option |
setMultiValued(boolean multiValued)
Sets whether or not this option can receive several values.
|
Option |
setRequired(boolean required)
Sets whether or not this option is mandatory.
|
Option |
setShortName(String shortName)
Sets the short name of this option.
|
Option |
setSingleValued(boolean singleValued)
Sets whether or not this option can receive a value.
|
JsonObject |
toJson()
Gets the json representation of this
Option. |
public static final String DEFAULT_ARG_NAME
public static final String NO_NAME
protected String longName
protected String shortName
protected String argName
protected String description
protected boolean required
MissingOptionException.protected boolean hidden
protected boolean singleValued
true by default.protected boolean multiValued
protected String defaultValue
protected boolean flag
true if the option is used in the command line.protected boolean help
public Option()
Option.public Option(Option other)
other - the other optionpublic Option(JsonObject json)
Option from the given JsonObjectjson - the json object representing the optiontoJson()public JsonObject toJson()
Option.public void ensureValidity()
CLI is valid before starting the parsing.
If the configuration is not valid, this method throws a IllegalArgumentException.public boolean acceptValue()
public String getName()
null for valid optionensureValidity()public boolean isMultiValued()
public Option setMultiValued(boolean multiValued)
multiValued - whether or not this option is multi-valued.Option instancepublic boolean isSingleValued()
public Option setSingleValued(boolean singleValued)
singleValued - whether or not this option is single-valued.Option instancepublic String getArgName()
null if not set.public Option setArgName(String argName)
argName - the arg name, must not be nullOption instancepublic String getDescription()
null if not set.public Option setDescription(String description)
description - the descriptionOption instancepublic boolean isHidden()
public Option setHidden(boolean hidden)
hidden - true to make this option hidden, false otherwiseOption instancepublic String getLongName()
null if not set.public Option setLongName(String longName)
longName - the long nameOption instancepublic boolean isRequired()
public Option setRequired(boolean required)
required - true to make this option mandatory, false otherwiseOption instancepublic String getShortName()
null if not set.public Option setShortName(String shortName)
shortName - the short nameOption instancepublic String getDefaultValue()
null if not set.public Option setDefaultValue(String defaultValue)
defaultValue - the default valueOption instancepublic boolean isFlag()
public Option setFlag(boolean flag)
Option to be a flag. It will be evaluated to true if it's found in
the command line. If you need a flag that may receive a value, use, in this order:
option.setFlag(true).setSingleValued(true)
flag - whether or not the option is a flag.Optionpublic boolean isHelp()
true if this option is a "help" option.public Option setHelp(boolean help)
help - true to set this option as a "Help" optionOptionpublic Set<String> getChoices()
public Option setChoices(Set<String> choices)
InvalidValueException exception is thrown.choices - the choicesOptionpublic Option addChoice(String choice)
InvalidValueException exception is thrown.choice - the choiceOptionCopyright © 2021 Eclipse. All rights reserved.