Class Option
java.lang.Object
io.vertx.core.cli.Option
- Direct Known Subclasses:
TypedOption
Models command line options. Options are values passed to a command line interface using -x or --x. Supported
syntaxes depend on the parser.
Short name is generally used with a single dash, while long name requires a double-dash.
- Author:
- Clement Escoffier invalid input: '<'[email protected]>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringthe option name used in usage message.if the option value has to be in a definited set, this field represents the set of values.static final StringDefault name in the usage message.protected Stringthe option default value.protected StringThe option description.protected booleanwhether or not the option is a flag.protected booleanwhether or not the option is a "help" option.protected booleanwhether or not the option is hidden.protected Stringthe option long name.protected booleanwhether or not the option can recevie multiple values.static final StringThe default long name / short name of the option.protected booleanwhether or not the option is required.protected Stringthe option short name.protected booleanwhether or not the option receives a single value. -
Constructor Summary
ConstructorsConstructorDescriptionOption()Creates a new empty instance ofOption.Option(JsonObject json) Creates a new instance ofOptionfrom the givenJsonObject -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a choice to the list of values accepted by this option.voidChecks whether or not the option is valid.getName()booleanisFlag()booleanisHelp()Checks whether or not this option is a "Help" option.booleanisHidden()booleanbooleanbooleansetArgName(String argName) Sets te arg name for this option.setChoices(Set<String> choices) Sets the list of values accepted by this option.setDefaultValue(String defaultValue) Sets the default value of this optionsetDescription(String description) Sets te description of this option.setFlag(boolean flag) Configures the currentOptionto be a flag.setHelp(boolean help) Sets whether or not this option is a "help" optionsetHidden(boolean hidden) Sets whether or not this option should be hiddensetLongName(String longName) Sets the long name of this option.setMultiValued(boolean multiValued) Sets whether or not this option can receive several values.setRequired(boolean required) Sets whether or not this option is mandatory.setShortName(String shortName) Sets the short name of this option.setSingleValued(boolean singleValued) Sets whether or not this option can receive a value.toJson()Gets the json representation of thisOption.
-
Field Details
-
DEFAULT_ARG_NAME
-
NO_NAME
The default long name / short name of the option. Notice that options requires at least a regular long name or short name.- See Also:
-
longName
the option long name. -
shortName
the option short name. -
argName
the option name used in usage message. -
description
The option description. -
required
protected boolean requiredwhether or not the option is required. A mandatory not set throws aMissingOptionException. -
singleValued
protected boolean singleValuedwhether or not the option receives a single value.trueby default. -
multiValued
protected boolean multiValuedwhether or not the option can recevie multiple values. -
defaultValue
the option default value. -
flag
protected boolean flagwhether or not the option is a flag. Flag option does not require a value. If an option is a flag, it is evaluated to} if the option is used in the command line.invalid @link
{@link true -
help
protected boolean helpwhether or not the option is a "help" option. Is the user execute the command line enabling a help option, the command line validation won't fail, and give the command the opportunity to display the usage message, instead of throwing an exception during the parsing. -
choices
-
-
Constructor Details
-
Option
public Option()Creates a new empty instance ofOption. -
Option
-
Option
Creates a new instance ofOptionfrom the givenJsonObject- Parameters:
json- the json object representing the option- See Also:
-
-
Method Details
-
toJson
Gets the json representation of thisOption.- Returns:
- the json representation
-
ensureValidity
public void ensureValidity()Checks whether or not the option is valid. This implementation check that it has a short name or a long name. This method is intended to be extended by sub-class. Parser should check that the set of option of aCLIis valid before starting the parsing. If the configuration is not valid, this method throws aIllegalArgumentException. -
acceptValue
public boolean acceptValue()- Returns:
- whether or not the option can receive a value.
-
getName
- Returns:
- the option name. It returns the long name if set, the short name otherwise. It cannot return
nullfor valid option - See Also:
-
isMultiValued
public boolean isMultiValued()- Returns:
- whether or not this option can receive several values.
-
setMultiValued
-
isSingleValued
public boolean isSingleValued()- Returns:
- whether or not this option is single valued.
-
setSingleValued
-
getArgName
- Returns:
- the option arg name used in usage messages,
nullif not set.
-
setArgName
-
getDescription
- Returns:
- the description of this option,
nullif not set.
-
setDescription
-
isHidden
public boolean isHidden()- Returns:
- whtehr or not this option is hidden.
-
setHidden
-
getLongName
- Returns:
- the option long name,
nullif not set.
-
setLongName
-
isRequired
public boolean isRequired()- Returns:
- whether or not this option is mandatory.
-
setRequired
-
getShortName
- Returns:
- the short name of this option,
nullif not set.
-
setShortName
-
getDefaultValue
- Returns:
- the default value of this option,
nullif not set.
-
setDefaultValue
-
isFlag
public boolean isFlag()- Returns:
- whether or not this option is a flag.
-
setFlag
-
isHelp
public boolean isHelp()Checks whether or not this option is a "Help" option.- Returns:
trueif this option is a "help" option.
-
setHelp
-
getChoices
-
setChoices
Sets the list of values accepted by this option. If the value set by the user does not match once of these values, aInvalidValueExceptionexception is thrown.- Parameters:
choices- the choices- Returns:
- the current
Option
-
addChoice
Adds a choice to the list of values accepted by this option. If the value set by the user does not match once of these values, aInvalidValueExceptionexception is thrown.- Parameters:
choice- the choice- Returns:
- the current
Option
-