Top Description Methods
io.vertx.core.cli

public Interface CLI

Known Direct Implementers
io.vertx.core.cli.impl.DefaultCLI
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.Fluent, .GenIgnore, .Nullable, .VertxGen, io.vertx.core.cli.annotations.CLIConfigurator, io.vertx.core.cli.impl.DefaultCLI, java.util.List

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.

Author
Clement Escoffier
See Also
Argument, Option

Method Summary

Modifier and TypeMethod and Description
public CLI

Returns:

the current CLI instance
addArgument
(Argument
the argument, must not be null
arg
)

Adds an argument.

public CLI

Returns:

the current CLI instance
addArguments
(List<Argument>
the arguments, must not be null
args
)

Adds a set of arguments.

public CLI

Returns:

the current CLI instance
addOption
(Option
the option, must not be null.
option
)

Adds an option.

public CLI

Returns:

the current CLI instance
addOptions
(List<Option>
the options, must not be null
options
)

Adds a set of options.

public static CLI

Returns:

the created instance of CLI
create
(String
the name of the CLI (must not be null)
name
)

Creates an instance of CLI using the default implementation.

public static CLI

Returns:

the created instance of CLI
create
(Class<?>
the annotated class
clazz
)

Creates an instance of CLI from the given Java class.

public @Nullable Argument

Returns:

the Argument, null if not found.
getArgument
(String
the name of the argument, must not be null
name
)

Gets an Argument based on its name (argument name).

public @Nullable Argument

Returns:

the Argument, null if not found.
getArgument
(int
the index, must be positive or zero.
index
)

Gets an Argument based on its index.

public List<Argument>

Returns:

the list of argument, empty if none.
getArguments
()

Gets the list of defined arguments.

public @Nullable String

Returns:

the CLI description.
getDescription
()

public String

Returns:

the CLI name.
getName
()

public @Nullable Option

Returns:

the Option, null if not found
getOption
(String
the name, must not be null
name
)

Gets an Option based on its name (short name, long name or argument name).

public List<Option>

Returns:

the list of options, empty if none.
getOptions
()

Gets the list of options.

public int

Returns:

the CLI priority.
getPriority
()

public @Nullable String

Returns:

the CLI summary.
getSummary
()

public boolean

Returns:

true if the current CLI is hidden, false otherwise
isHidden
()

Checks whether or not the current CLI instance is hidden.

public CommandLine

Returns:

the creates command line
parse
(List<String>
the arguments
arguments
)

Parses the user command line interface and create a new CommandLine containing extracting values.

public CommandLine

Returns:

the creates command line
parse
(List<String>
the arguments
arguments
,
boolean
enable / disable parsing validation
validate
)

Parses the user command line interface and create a new CommandLine containing extracting values.

public CLI

Returns:

the current CLI instance
removeArgument
(int
the argument index
index
)

Removes an argument identified by its index.

public CLI

Returns:

the current CLI instance
removeOption
(String
the option name
name
)

Removes an option identified by its name.

public CLI

Returns:

the current CLI instance
setArguments
(List<Argument>
the list of arguments, must not be null
args
)

Sets the list of arguments.

public CLI
public CLI

Returns:

the current CLI instance
setHidden
(boolean
enables or disables the hidden aspect of the CI
hidden
)

Sets whether or not the current instance of CLI must be hidden.

public CLI

Returns:

the current CLI instance
setName
(String
the name
name
)

Sets the name of the CLI.

public CLI

Returns:

the current CLI instance
setOptions
(List<Option>
the list of options, must not be null
options
)

Sets the list of arguments.

public CLI

Returns:

the current CLI instance
setPriority
(int
the priority
priority
)

Sets the priority of the CLI.

public CLI

Returns:

the current CLI instance
setSummary
(String
the summary
summary
)

Sets the summary of the CLI.

public CLI

Returns:

the current CLI instance
usage
(StringBuilder
the string builder in which the help is going to be printed
builder
)

Generates the usage / help of the current CLI.

public CLI

Returns:

the current CLI instance
usage
(StringBuilder
the string builder in which the help is going to be printed
builder
,
String
an optional prefix
prefix
)

Generates the usage / help of the current CLI.

Method Detail

addArgumentback to summary
public CLI addArgument(Argument arg)

Adds an argument.

Parameters
arg:Argument

the argument, must not be null

Returns:CLI

the current CLI instance

Annotations
@Fluent
addArgumentsback to summary
public CLI addArguments(List<Argument> args)

Adds a set of arguments. Unlike setArguments(List), this method does not remove the existing arguments. The given list is appended to the existing list.

Parameters
args:List<Argument>

the arguments, must not be null

Returns:CLI

the current CLI instance

Annotations
@Fluent
addOptionback to summary
public CLI addOption(Option option)

Adds an option.

Parameters
option:Option

the option, must not be null.

Returns:CLI

the current CLI instance

Annotations
@Fluent
addOptionsback to summary
public CLI addOptions(List<Option> options)

Adds a set of options. Unlike setOptions(List)}, this method does not remove the existing options. The given list is appended to the existing list.

Parameters
options:List<Option>

the options, must not be null

Returns:CLI

the current CLI instance

Annotations
@Fluent
createback to summary
public static CLI create(String name)

Creates an instance of CLI using the default implementation.

Parameters
name:String

the name of the CLI (must not be null)

Returns:CLI

the created instance of CLI

createback to summary
public static CLI create(Class<?> clazz)

Creates an instance of CLI from the given Java class. It instantiates the CLI object from the annotations used in the class.

Parameters
clazz:Class<?>

the annotated class

Returns:CLI

the created instance of CLI

Annotations
@GenIgnore
getArgumentback to summary
public @Nullable Argument getArgument(String name)

Gets an Argument based on its name (argument name).

Parameters
name:String

the name of the argument, must not be null

Returns:@Nullable Argument

the Argument, null if not found.

getArgumentback to summary
public @Nullable Argument getArgument(int index)

Gets an Argument based on its index.

Parameters
index:int

the index, must be positive or zero.

Returns:@Nullable Argument

the Argument, null if not found.

getArgumentsback to summary
public List<Argument> getArguments()

Gets the list of defined arguments.

Returns:List<Argument>

the list of argument, empty if none.

getDescriptionback to summary
public @Nullable String getDescription()
Returns:@Nullable String

the CLI description.

getNameback to summary
public String getName()
Returns:String

the CLI name.

getOptionback to summary
public @Nullable Option getOption(String name)

Gets an Option based on its name (short name, long name or argument name).

Parameters
name:String

the name, must not be null

Returns:@Nullable Option

the Option, null if not found

getOptionsback to summary
public List<Option> getOptions()

Gets the list of options.

Returns:List<Option>

the list of options, empty if none.

getPriorityback to summary
public int getPriority()
Returns:int

the CLI priority.

getSummaryback to summary
public @Nullable String getSummary()
Returns:@Nullable String

the CLI summary.

isHiddenback to summary
public boolean isHidden()

Checks whether or not the current CLI instance is hidden.

Returns:boolean

true if the current CLI is hidden, false otherwise

parseback to summary
public CommandLine parse(List<String> arguments)

Parses the user command line interface and create a new CommandLine containing extracting values.

Parameters
arguments:List<String>

the arguments

Returns:CommandLine

the creates command line

parseback to summary
public CommandLine parse(List<String> arguments, boolean validate)

Parses the user command line interface and create a new CommandLine containing extracting values.

Parameters
arguments:List<String>

the arguments

validate:boolean

enable / disable parsing validation

Returns:CommandLine

the creates command line

removeArgumentback to summary
public CLI removeArgument(int index)

Removes an argument identified by its index. This method does nothing if the argument cannot be found.

Parameters
index:int

the argument index

Returns:CLI

the current CLI instance

Annotations
@Fluent
removeOptionback to summary
public CLI removeOption(String name)

Removes an option identified by its name. This method does nothing if the option cannot be found.

Parameters
name:String

the option name

Returns:CLI

the current CLI instance

Annotations
@Fluent
setArgumentsback to summary
public CLI setArguments(List<Argument> args)

Sets the list of arguments.

Parameters
args:List<Argument>

the list of arguments, must not be null

Returns:CLI

the current CLI instance

Annotations
@Fluent
setDescriptionback to summary
public CLI setDescription(String desc)
Annotations
@Fluent
setHiddenback to summary
public CLI setHidden(boolean hidden)

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.

Parameters
hidden:boolean

enables or disables the hidden aspect of the CI

Returns:CLI

the current CLI instance

Annotations
@Fluent
setNameback to summary
public CLI setName(String name)

Sets the name of the CLI.

Parameters
name:String

the name

Returns:CLI

the current CLI instance

Annotations
@Fluent
setOptionsback to summary
public CLI setOptions(List<Option> options)

Sets the list of arguments.

Parameters
options:List<Option>

the list of options, must not be null

Returns:CLI

the current CLI instance

Annotations
@Fluent
setPriorityback to summary
public CLI setPriority(int priority)

Sets the priority of the CLI.

Parameters
priority:int

the priority

Returns:CLI

the current CLI instance

Annotations
@Fluent
setSummaryback to summary
public CLI setSummary(String summary)

Sets the summary of the CLI.

Parameters
summary:String

the summary

Returns:CLI

the current CLI instance

Annotations
@Fluent
usageback to summary
public CLI usage(StringBuilder builder)

Generates the usage / help of the current CLI.

Parameters
builder:StringBuilder

the string builder in which the help is going to be printed

Returns:CLI

the current CLI instance

Annotations
@GenIgnore
usageback to summary
public CLI usage(StringBuilder builder, String prefix)

Generates the usage / help of the current CLI.

Parameters
builder:StringBuilder

the string builder in which the help is going to be printed

prefix:String

an optional prefix

Returns:CLI

the current CLI instance

Annotations
@GenIgnore