Top Description Fields Constructors Methods
io.vertx.core.cli

public Class Option

extends Object
Class Inheritance
Known Direct Subclasses
io.vertx.core.cli.TypedOption
Annotations
@DataObject
@JsonGen
publicConverter:false
Imports
io.vertx.codegen.annotations.DataObject, io.vertx.codegen.json.annotations.JsonGen, io.vertx.core.json.JsonObject, java.util.Objects, .Set, .TreeSet

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

Field Summary

Modifier and TypeField 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.

public static final 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.

public static final 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 Summary

AccessConstructor and Description
public
Option()

Creates a new empty instance of Option.

public
Option(Option
the other option
other
)

Creates a new instance of Option by copying the state of another Option.

public
Option(JsonObject
the json object representing the option
json
)
References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

Creates a new instance of Option from the given JsonObject

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

whether or not the option can receive a value.
acceptValue
()

public Option

Returns:

the current Option
addChoice
(String
the choice
choice
)

Adds a choice to the list of values accepted by this option.

public void
ensureValidity()

Checks whether or not the option is valid.

public String

Returns:

the option arg name used in usage messages, null if not set.
getArgName
()

public Set<String>

Returns:

get the list of choices for the given option. Empty if this option does not define choices.
getChoices
()

public String

Returns:

the default value of this option, null if not set.
getDefaultValue
()

public String

Returns:

the description of this option, null if not set.
getDescription
()

public String

Returns:

the option long name, null if not set.
getLongName
()

public String

Returns:

the option name. It returns the long name if set, the short name otherwise. It cannot return null for valid option
getName
()

public String

Returns:

the short name of this option, null if not set.
getShortName
()

public boolean

Returns:

whether or not this option is a flag.
isFlag
()

public boolean

Returns:

true if this option is a "help" option.
isHelp
()

Checks whether or not this option is a "Help" option.

public boolean

Returns:

whtehr or not this option is hidden.
isHidden
()

public boolean

Returns:

whether or not this option can receive several values.
isMultiValued
()

public boolean

Returns:

whether or not this option is mandatory.
isRequired
()

public boolean

Returns:

whether or not this option is single valued.
isSingleValued
()

public Option

Returns:

the current Option instance
setArgName
(String
the arg name, must not be null
argName
)

Sets te arg name for this option.

public Option

Returns:

the current Option
setChoices
(Set<String>
the choices
choices
)

Sets the list of values accepted by this option.

public Option

Returns:

the current Option instance
setDefaultValue
(String
the default value
defaultValue
)

Sets the default value of this option

public Option

Returns:

the current Option instance
setDescription
(String
the description
description
)

Sets te description of this option.

public Option

Returns:

the current Option
setFlag
(boolean
whether or not the option is a flag.
flag
)

Configures the current Option to be a flag.

public Option

Returns:

the current Option
setHelp
(boolean
true to set this option as a "Help" option
help
)

Sets whether or not this option is a "help" option

public Option

Returns:

the current Option instance
setHidden
(boolean
true to make this option hidden, false otherwise
hidden
)

Sets whether or not this option should be hidden

public Option

Returns:

the current Option instance
setLongName
(String
the long name
longName
)

Sets the long name of this option.

public Option

Returns:

the current Option instance
setMultiValued
(boolean
whether or not this option is multi-valued.
multiValued
)

Sets whether or not this option can receive several values.

public Option

Returns:

the current Option instance
setRequired
(boolean
true to make this option mandatory, false otherwise
required
)

Sets whether or not this option is mandatory.

public Option

Returns:

the current Option instance
setShortName
(String
the short name
shortName
)

Sets the short name of this option.

public Option

Returns:

the current Option instance
setSingleValued
(boolean
whether or not this option is single-valued.
singleValued
)

Sets whether or not this option can receive a value.

public JsonObject

Returns:

the json representation
toJson
()
References Deprecated JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

Gets the json representation of this Option.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

argNameback to summary
protected String argName

the option name used in usage message.

choicesback to summary
protected Set<String> choices

if the option value has to be in a definited set, this field represents the set of values. Value are sorted alphabetically.

DEFAULT_ARG_NAMEback to summary
public static final String DEFAULT_ARG_NAME

Default name in the usage message.

defaultValueback to summary
protected String defaultValue

the option default value.

descriptionback to summary
protected String description

The option description.

flagback to summary
protected boolean flag

whether or not the option is a flag. Flag option does not require a value. If an option is a flag, it is evaluated to true if the option is used in the command line.

helpback to summary
protected boolean help

whether 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.

hiddenback to summary
protected boolean hidden

whether or not the option is hidden. Hidden options are not displayed in usage.

longNameback to summary
protected String longName

the option long name.

multiValuedback to summary
protected boolean multiValued

whether or not the option can recevie multiple values.

NO_NAMEback to summary
public static final String NO_NAME

The default long name / short name of the option. Notice that options requires at least a regular long name or short name.

requiredback to summary
protected boolean required

whether or not the option is required. A mandatory not set throws a MissingOptionException.

shortNameback to summary
protected String shortName

the option short name.

singleValuedback to summary
protected boolean singleValued

whether or not the option receives a single value. true by default.

Constructor Detail

Optionback to summary
public Option()

Creates a new empty instance of Option.

Optionback to summary
public Option(Option other)

Creates a new instance of Option by copying the state of another Option.

Parameters
other:Option

the other option

Optionback to summary
public Option(JsonObject json)

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Creates a new instance of Option from the given JsonObject

Parameters
json:JsonObject

the json object representing the option

See Also
toJson()

Method Detail

acceptValueback to summary
public boolean acceptValue()
Returns:boolean

whether or not the option can receive a value.

addChoiceback to summary
public Option addChoice(String choice)

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, a InvalidValueException exception is thrown.

Parameters
choice:String

the choice

Returns:Option

the current Option

ensureValidityback to summary
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 a CLI is valid before starting the parsing.

If the configuration is not valid, this method throws a IllegalArgumentException.

getArgNameback to summary
public String getArgName()
Returns:String

the option arg name used in usage messages, null if not set.

getChoicesback to summary
public Set<String> getChoices()
Returns:Set<String>

get the list of choices for the given option. Empty if this option does not define choices.

getDefaultValueback to summary
public String getDefaultValue()
Returns:String

the default value of this option, null if not set.

getDescriptionback to summary
public String getDescription()
Returns:String

the description of this option, null if not set.

getLongNameback to summary
public String getLongName()
Returns:String

the option long name, null if not set.

getNameback to summary
public String getName()
Returns:String

the option name. It returns the long name if set, the short name otherwise. It cannot return null for valid option

See Also
ensureValidity()
getShortNameback to summary
public String getShortName()
Returns:String

the short name of this option, null if not set.

isFlagback to summary
public boolean isFlag()
Returns:boolean

whether or not this option is a flag.

isHelpback to summary
public boolean isHelp()

Checks whether or not this option is a "Help" option.

Returns:boolean

true if this option is a "help" option.

isHiddenback to summary
public boolean isHidden()
Returns:boolean

whtehr or not this option is hidden.

isMultiValuedback to summary
public boolean isMultiValued()
Returns:boolean

whether or not this option can receive several values.

isRequiredback to summary
public boolean isRequired()
Returns:boolean

whether or not this option is mandatory.

isSingleValuedback to summary
public boolean isSingleValued()
Returns:boolean

whether or not this option is single valued.

setArgNameback to summary
public Option setArgName(String argName)

Sets te arg name for this option.

Parameters
argName:String

the arg name, must not be null

Returns:Option

the current Option instance

setChoicesback to summary
public Option setChoices(Set<String> choices)

Sets the list of values accepted by this option. If the value set by the user does not match once of these values, a InvalidValueException exception is thrown.

Parameters
choices:Set<String>

the choices

Returns:Option

the current Option

setDefaultValueback to summary
public Option setDefaultValue(String defaultValue)

Sets the default value of this option

Parameters
defaultValue:String

the default value

Returns:Option

the current Option instance

setDescriptionback to summary
public Option setDescription(String description)

Sets te description of this option.

Parameters
description:String

the description

Returns:Option

the current Option instance

setFlagback to summary
public Option setFlag(boolean flag)

Configures the current 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)
Parameters
flag:boolean

whether or not the option is a flag.

Returns:Option

the current Option

setHelpback to summary
public Option setHelp(boolean help)

Sets whether or not this option is a "help" option

Parameters
help:boolean

true to set this option as a "Help" option

Returns:Option

the current Option

setHiddenback to summary
public Option setHidden(boolean hidden)

Sets whether or not this option should be hidden

Parameters
hidden:boolean

true to make this option hidden, false otherwise

Returns:Option

the current Option instance

setLongNameback to summary
public Option setLongName(String longName)

Sets the long name of this option.

Parameters
longName:String

the long name

Returns:Option

the current Option instance

setMultiValuedback to summary
public Option setMultiValued(boolean multiValued)

Sets whether or not this option can receive several values.

Parameters
multiValued:boolean

whether or not this option is multi-valued.

Returns:Option

the current Option instance

setRequiredback to summary
public Option setRequired(boolean required)

Sets whether or not this option is mandatory.

Parameters
required:boolean

true to make this option mandatory, false otherwise

Returns:Option

the current Option instance

setShortNameback to summary
public Option setShortName(String shortName)

Sets the short name of this option.

Parameters
shortName:String

the short name

Returns:Option

the current Option instance

setSingleValuedback to summary
public Option setSingleValued(boolean singleValued)

Sets whether or not this option can receive a value.

Parameters
singleValued:boolean

whether or not this option is single-valued.

Returns:Option

the current Option instance

toJsonback to summary
public JsonObject toJson()

References Deprecated

JsonObject is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Gets the json representation of this Option.

Returns:JsonObject

the json representation