Interface defining a command-line interface (in other words a command such as 'run', 'ls'...). This interface is polyglot to ease reuse such as in Vert.x Shell.
A command line interface has a name, and defines a set of options and arguments. Options are key-value pair such as-foo=bar
or -flag
. The supported formats depend on the used parser. Arguments are unlike
options raw values. Options are defined using
Option, while argument are defined using Argument.
Command line interfaces also define a summary and a description. These attributes are used in the usage generation
. To disable the help generation, set the hidden
attribute to true
.
Command Line Interface object does not contains "value", it's a model. It must be evaluated by a
parser that returns a CommandLine object containing the argument and option values.
Constructor and description |
---|
CLI
(java.lang.Object delegate) |
Type | Name and description | ||||
---|---|---|---|---|---|
CLI |
addArgument(java.util.Map<java.lang.String, java.lang.Object> arg = [:]) Adds an argument. |
||||
CLI |
addArguments(java.util.List<java.util.Map<java.lang.String, java.lang.Object>> args) Adds a set of arguments. |
||||
CLI |
addOption(java.util.Map<java.lang.String, java.lang.Object> option = [:]) Adds an option. |
||||
CLI |
addOptions(java.util.List<java.util.Map<java.lang.String, java.lang.Object>> options) Adds a set of options. |
||||
static CLI |
create(java.lang.String name) Creates an instance of CLI using the default implementation. |
||||
java.util.Map<java.lang.String, java.lang.Object> |
getArgument(java.lang.String name) Gets an | java.util.Map<java.lang.String, java.lang.Object> |
getArgument(int index) Gets an | java.util.List<java.util.Map<java.lang.String, java.lang.Object>> |
getArguments() Gets the list of defined arguments. |
java.lang.Object |
getDelegate() |
||||
java.lang.String |
getDescription()
|
||||
java.lang.String |
getName()
|
||||
java.util.Map<java.lang.String, java.lang.Object> |
getOption(java.lang.String name) Gets an | java.util.List<java.util.Map<java.lang.String, java.lang.Object>> |
getOptions() Gets the list of options. |
||
java.lang.String |
getSummary()
|
||||
boolean |
isHidden() Checks whether or not the current CLI instance is hidden. |
||||
CommandLine |
parse(java.util.List<java.lang.String> arguments) Parses the user command line interface and create a new CommandLine containing extracting values. |
||||
CommandLine |
parse(java.util.List<java.lang.String> arguments, boolean validate) Parses the user command line interface and create a new CommandLine containing extracting values. |
||||
CLI |
removeArgument(int index) Removes an argument identified by its index. |
||||
CLI |
removeOption(java.lang.String name) Removes an option identified by its name. |
||||
CLI |
setArguments(java.util.List<java.util.Map<java.lang.String, java.lang.Object>> args) Sets the list of arguments. |
||||
CLI |
setDescription(java.lang.String desc) |
||||
CLI |
setHidden(boolean hidden) Sets whether or not the current instance of CLI must be hidden. |
||||
CLI |
setName(java.lang.String name) Sets the name of the CLI. |
||||
CLI |
setOptions(java.util.List<java.util.Map<java.lang.String, java.lang.Object>> options) Sets the list of arguments. |
||||
CLI |
setSummary(java.lang.String summary) Sets the summary of the CLI. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Adds an argument.
arg
- the argument, must not be null
(see Argument)Adds a set of arguments. Unlike CLI.setArguments, this method does not remove the existing arguments. The given list is appended to the existing list.
args
- the arguments, must not be null
Adds an option.
option
- the option, must not be null
. (see Option)Adds a set of options. Unlike CLI.setOptions}, this method does not remove the existing options. The given list is appended to the existing list.
options
- the options, must not be null
Creates an instance of CLI using the default implementation.
name
- the name of the CLI (must not be null
)Gets an Argument based on its name (argument name).
name
- the name of the argument, must not be null
Gets an Argument based on its index.
index
- the index, must be positive or zero.Gets the list of defined arguments.
Gets an Option based on its name (short name, long name or argument name).
name
- the name, must not be null
Gets the list of options.
Checks whether or not the current CLI instance is hidden.
true
if the current CLI is hidden, otherwiseParses the user command line interface and create a new CommandLine containing extracting values.
arguments
- the argumentsParses the user command line interface and create a new CommandLine containing extracting values.
arguments
- the argumentsvalidate
- enable / disable parsing validationRemoves an argument identified by its index. This method does nothing if the argument cannot be found.
index
- the argument indexRemoves an option identified by its name. This method does nothing if the option cannot be found.
name
- the option nameSets the list of arguments.
args
- the list of arguments, must not be null
Sets whether or not the current instance of CLI must be hidden. Hidden CLI are not listed when displaying usages / help messages. In other words, hidden commands are for power user.
hidden
- enables or disables the hidden aspect of the CISets the name of the CLI.
name
- the nameSets the list of arguments.
options
- the list of options, must not be null