Package io.vertx.core.cli
Class TypedOption<T>
- java.lang.Object
-
- io.vertx.core.cli.Option
-
- io.vertx.core.cli.TypedOption<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected Converter<T>
converter
the converter to create the value.protected String
listSeparator
the split character used if the raw value needs to be parsed as a list.protected boolean
parsedAsList
whether or not the raw value should be parsed as a list.protected Class<T>
type
The type of the option.-
Fields inherited from class io.vertx.core.cli.Option
argName, choices, DEFAULT_ARG_NAME, defaultValue, description, flag, help, hidden, longName, multiValued, NO_NAME, required, shortName, singleValued
-
-
Constructor Summary
Constructors Constructor Description TypedOption()
Creates an empty instance ofTypedOption
.TypedOption(TypedOption<T> option)
Creates an instance ofTypedOption
by copying the state of anotherTypedOption
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypedOption<T>
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.Converter<T>
getConverter()
String
getListSeparator()
Class<T>
getType()
boolean
isParsedAsList()
TypedOption<T>
setArgName(String argName)
Sets te arg name for this option.TypedOption<T>
setChoices(Set<String> choices)
Sets the list of values accepted by this option.TypedOption<T>
setConverter(Converter<T> converter)
TypedOption<T>
setDefaultValue(String defaultValue)
Sets the default value of this optionTypedOption<T>
setDescription(String description)
Sets te description of this option.TypedOption<T>
setFlag(boolean flag)
Configures the currentOption
to be a flag.TypedOption<T>
setHidden(boolean hidden)
Sets whether or not this option should be hiddenTypedOption<T>
setListSeparator(String listSeparator)
TypedOption<T>
setLongName(String longName)
Sets the long name of this option.TypedOption<T>
setMultiValued(boolean acceptMultipleValues)
Sets whether or not this option can receive several values.TypedOption<T>
setParsedAsList(boolean isList)
TypedOption<T>
setRequired(boolean required)
Sets whether or not this option is mandatory.TypedOption<T>
setShortName(String shortName)
Sets the short name of this option.TypedOption<T>
setSingleValued(boolean acceptSingleValue)
Sets whether or not this option can receive a value.TypedOption<T>
setType(Class<T> type)
-
Methods inherited from class io.vertx.core.cli.Option
acceptValue, getArgName, getChoices, getDefaultValue, getDescription, getLongName, getName, getShortName, isFlag, isHelp, isHidden, isMultiValued, isRequired, isSingleValued, setHelp, toJson
-
-
-
-
Field Detail
-
parsedAsList
protected boolean parsedAsList
whether or not the raw value should be parsed as a list. The list if computed by splitting the value.
-
listSeparator
protected String listSeparator
the split character used if the raw value needs to be parsed as a list.','
is used by default.
-
-
Constructor Detail
-
TypedOption
public TypedOption()
Creates an empty instance ofTypedOption
.
-
TypedOption
public TypedOption(TypedOption<T> option)
Creates an instance ofTypedOption
by copying the state of anotherTypedOption
- Parameters:
option
- the copied option
-
-
Method Detail
-
setMultiValued
public TypedOption<T> setMultiValued(boolean acceptMultipleValues)
Description copied from class:Option
Sets whether or not this option can receive several values.- Overrides:
setMultiValued
in classOption
- Parameters:
acceptMultipleValues
- whether or not this option is multi-valued.- Returns:
- the current
Option
instance
-
setSingleValued
public TypedOption<T> setSingleValued(boolean acceptSingleValue)
Description copied from class:Option
Sets whether or not this option can receive a value.- Overrides:
setSingleValued
in classOption
- Parameters:
acceptSingleValue
- whether or not this option is single-valued.- Returns:
- the current
Option
instance
-
setArgName
public TypedOption<T> setArgName(String argName)
Description copied from class:Option
Sets te arg name for this option.- Overrides:
setArgName
in classOption
- Parameters:
argName
- the arg name, must not benull
- Returns:
- the current
Option
instance
-
setDefaultValue
public TypedOption<T> setDefaultValue(String defaultValue)
Description copied from class:Option
Sets the default value of this option- Overrides:
setDefaultValue
in classOption
- Parameters:
defaultValue
- the default value- Returns:
- the current
Option
instance
-
setDescription
public TypedOption<T> setDescription(String description)
Description copied from class:Option
Sets te description of this option.- Overrides:
setDescription
in classOption
- Parameters:
description
- the description- Returns:
- the current
Option
instance
-
setFlag
public TypedOption<T> setFlag(boolean flag)
Description copied from class:Option
Configures the currentOption
to be a flag. It will be evaluated totrue
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)
-
setHidden
public TypedOption<T> setHidden(boolean hidden)
Description copied from class:Option
Sets whether or not this option should be hidden
-
setLongName
public TypedOption<T> setLongName(String longName)
Description copied from class:Option
Sets the long name of this option.- Overrides:
setLongName
in classOption
- Parameters:
longName
- the long name- Returns:
- the current
Option
instance
-
setRequired
public TypedOption<T> setRequired(boolean required)
Description copied from class:Option
Sets whether or not this option is mandatory.- Overrides:
setRequired
in classOption
- Parameters:
required
-true
to make this option mandatory, {@link false} otherwise- Returns:
- the current
Option
instance
-
setShortName
public TypedOption<T> setShortName(String shortName)
Description copied from class:Option
Sets the short name of this option.- Overrides:
setShortName
in classOption
- Parameters:
shortName
- the short name- Returns:
- the current
Option
instance
-
setType
public TypedOption<T> setType(Class<T> type)
-
isParsedAsList
public boolean isParsedAsList()
-
setParsedAsList
public TypedOption<T> setParsedAsList(boolean isList)
-
getListSeparator
public String getListSeparator()
-
setListSeparator
public TypedOption<T> setListSeparator(String listSeparator)
-
setConverter
public TypedOption<T> setConverter(Converter<T> converter)
-
ensureValidity
public void ensureValidity()
Description copied from class:Option
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 aCLI
is valid before starting the parsing. If the configuration is not valid, this method throws aIllegalArgumentException
.- Overrides:
ensureValidity
in classOption
-
setChoices
public TypedOption<T> setChoices(Set<String> choices)
Description copied from class:Option
Sets the list of values accepted by this option. If the value set by the user does not match once of these values, aInvalidValueException
exception is thrown.- Overrides:
setChoices
in classOption
- Parameters:
choices
- the choices- Returns:
- the current
Option
-
addChoice
public TypedOption<T> addChoice(String choice)
Description copied from class:Option
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, aInvalidValueException
exception is thrown.
-
-