Package io.vertx.core.cli
Class Argument
- java.lang.Object
-
- io.vertx.core.cli.Argument
-
- Direct Known Subclasses:
TypedArgument
public class Argument extends Object
Defines a command line argument. Unlike options, argument don't have names and are identified using an index. The first index is 0 (because we are in the computer world).- Author:
- Clement Escoffier
- See Also:
Option
-
-
Field Summary
Fields Modifier and Type Field Description protected String
argName
The argument name used in the usage.static String
DEFAULT_ARG_NAME
The default argument name displayed in the usage.protected String
defaultValue
The optional default value of this argument.protected String
description
The argument description.protected boolean
hidden
Whether or not this argument is hidden.protected int
index
The argument index.protected boolean
multiValued
Whether or not this argument can receive multiple value.protected boolean
required
Whether or not this argument is mandatory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
ensureValidity()
Checks that the argument configuration is valid.String
getArgName()
String
getDefaultValue()
String
getDescription()
int
getIndex()
boolean
isHidden()
boolean
isMultiValued()
boolean
isRequired()
Argument
setArgName(String argName)
Sets the argument name of thisArgument
.Argument
setDefaultValue(String defaultValue)
Sets the default value of thisArgument
.Argument
setDescription(String description)
Sets the description of theArgument
.Argument
setHidden(boolean hidden)
Sets whether or not the currentArgument
is hidden.Argument
setIndex(int index)
Sets the argument index.Argument
setMultiValued(boolean multiValued)
Sets whether or not the argument can receive several values.Argument
setRequired(boolean required)
Sets whether or not the currentArgument
is required.JsonObject
toJson()
Exports thisArgument
to its corresponding JSON representation.
-
-
-
Field Detail
-
DEFAULT_ARG_NAME
public static final String DEFAULT_ARG_NAME
The default argument name displayed in the usage.- See Also:
- Constant Field Values
-
index
protected int index
The argument index. Must be positive or null. It is set fo -1 by default to check that the index was set.
-
argName
protected String argName
The argument name used in the usage.
-
description
protected String description
The argument description.
-
hidden
protected boolean hidden
Whether or not this argument is hidden. Hidden argument are not shown in the usage.
-
required
protected boolean required
Whether or not this argument is mandatory. Mandatory arguments throw aMissingValueException
if the user command line does not provide a value.
-
defaultValue
protected String defaultValue
The optional default value of this argument.
-
multiValued
protected boolean multiValued
Whether or not this argument can receive multiple value. Only the last argument can receive multiple values.
-
-
Constructor Detail
-
Argument
public Argument()
Creates a new empty instance ofArgument
.
-
Argument
public Argument(Argument other)
Creates a new instance ofArgument
by copyingother
.- Parameters:
other
- the argument to copy
-
Argument
public Argument(JsonObject json)
Creates a new instance ofArgument
from the given JSON object.- Parameters:
json
- the json object- See Also:
toJson()
-
-
Method Detail
-
toJson
public JsonObject toJson()
Exports thisArgument
to its corresponding JSON representation.- Returns:
- the json object representing this
Argument
- See Also:
Argument(JsonObject)
-
getArgName
public String getArgName()
- Returns:
- the arg name,
null
if not defined.
-
setArgName
public Argument setArgName(String argName)
Sets the argument name of thisArgument
.- Parameters:
argName
- the argument name, must not benull
- Returns:
- the current
Argument
instance
-
getDescription
public String getDescription()
- Returns:
- the description,
null
if not defined.
-
setDescription
public Argument setDescription(String description)
Sets the description of theArgument
.- Parameters:
description
- the description- Returns:
- the current
Argument
instance
-
isHidden
public boolean isHidden()
- Returns:
- whether or not the current
Argument
is hidden.
-
setHidden
public Argument setHidden(boolean hidden)
Sets whether or not the currentArgument
is hidden.
-
getIndex
public int getIndex()
- Returns:
- the argument index.
-
setIndex
public Argument setIndex(int index)
Sets the argument index.- Parameters:
index
- the index, must not be negative- Returns:
- the current
Argument
instance
-
isRequired
public boolean isRequired()
- Returns:
- whether or not the current
Argument
is required.
-
setRequired
public Argument setRequired(boolean required)
Sets whether or not the currentArgument
is required.- Parameters:
required
-true
to make this argument mandatory, {@link false} otherwise- Returns:
- the current
Argument
instance
-
getDefaultValue
public String getDefaultValue()
- Returns:
- the argument default value,
null
if not specified.
-
setDefaultValue
public Argument setDefaultValue(String defaultValue)
Sets the default value of thisArgument
.- Parameters:
defaultValue
- the default value- Returns:
- the current
Argument
instance
-
isMultiValued
public boolean isMultiValued()
- Returns:
- whether or not the argument can receive several values.
-
setMultiValued
public Argument setMultiValued(boolean multiValued)
Sets whether or not the argument can receive several values. Only the last argument can receive several values.- Parameters:
multiValued
-true
to mark this argument as multi-valued.- Returns:
- the current
Argument
instance
-
ensureValidity
public void ensureValidity()
Checks that the argument configuration is valid. This method is mainly made for children classes adding constraint to the configuration. The parser verifies that arguments are valid before starting the parsing. If the configuration is not valid, this method throws aIllegalArgumentException
.
-
-