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 StringargNameThe argument name used in the usage.static StringDEFAULT_ARG_NAMEThe default argument name displayed in the usage.protected StringdefaultValueThe optional default value of this argument.protected StringdescriptionThe argument description.protected booleanhiddenWhether or not this argument is hidden.protected intindexThe argument index.protected booleanmultiValuedWhether or not this argument can receive multiple value.protected booleanrequiredWhether or not this argument is mandatory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidensureValidity()Checks that the argument configuration is valid.StringgetArgName()StringgetDefaultValue()StringgetDescription()intgetIndex()booleanisHidden()booleanisMultiValued()booleanisRequired()ArgumentsetArgName(String argName)Sets the argument name of thisArgument.ArgumentsetDefaultValue(String defaultValue)Sets the default value of thisArgument.ArgumentsetDescription(String description)Sets the description of theArgument.ArgumentsetHidden(boolean hidden)Sets whether or not the currentArgumentis hidden.ArgumentsetIndex(int index)Sets the argument index.ArgumentsetMultiValued(boolean multiValued)Sets whether or not the argument can receive several values.ArgumentsetRequired(boolean required)Sets whether or not the currentArgumentis required.JsonObjecttoJson()Exports thisArgumentto 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 aMissingValueExceptionif 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 ofArgumentby copyingother.- Parameters:
other- the argument to copy
-
Argument
public Argument(JsonObject json)
Creates a new instance ofArgumentfrom the given JSON object.- Parameters:
json- the json object- See Also:
toJson()
-
-
Method Detail
-
toJson
public JsonObject toJson()
Exports thisArgumentto its corresponding JSON representation.- Returns:
- the json object representing this
Argument - See Also:
Argument(JsonObject)
-
getArgName
public String getArgName()
- Returns:
- the arg name,
nullif 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
Argumentinstance
-
getDescription
public String getDescription()
- Returns:
- the description,
nullif not defined.
-
setDescription
public Argument setDescription(String description)
Sets the description of theArgument.- Parameters:
description- the description- Returns:
- the current
Argumentinstance
-
isHidden
public boolean isHidden()
- Returns:
- whether or not the current
Argumentis hidden.
-
setHidden
public Argument setHidden(boolean hidden)
Sets whether or not the currentArgumentis 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
Argumentinstance
-
isRequired
public boolean isRequired()
- Returns:
- whether or not the current
Argumentis required.
-
setRequired
public Argument setRequired(boolean required)
Sets whether or not the currentArgumentis required.- Parameters:
required-trueto make this argument mandatory, {@link false} otherwise- Returns:
- the current
Argumentinstance
-
getDefaultValue
public String getDefaultValue()
- Returns:
- the argument default value,
nullif not specified.
-
setDefaultValue
public Argument setDefaultValue(String defaultValue)
Sets the default value of thisArgument.- Parameters:
defaultValue- the default value- Returns:
- the current
Argumentinstance
-
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-trueto mark this argument as multi-valued.- Returns:
- the current
Argumentinstance
-
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.
-
-