Package io.vertx.core.cli
Interface CLI
-
public interface CLIInterface 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=baror-flag. The supported formats depend on the used parser. Arguments are unlike options raw values. Options are defined usingOption, while argument are defined usingArgument. Command line interfaces also define a summary and a description. These attributes are used in the usage generation . To disable the help generation, set thehiddenattribute totrue. Command Line Interface object does not contains "value", it's a model. It must be evaluated by a parser that returns aCommandLineobject containing the argument and option values.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description CLIaddArgument(Argument arg)Adds an argument.CLIaddArguments(List<Argument> args)Adds a set of arguments.CLIaddOption(Option option)Adds an option.CLIaddOptions(List<Option> options)Adds a set of options.static CLIcreate(Class<?> clazz)Creates an instance ofCLIfrom the given Java class.static CLIcreate(String name)Creates an instance ofCLIusing the default implementation.ArgumentgetArgument(int index)Gets anArgumentbased on its index.ArgumentgetArgument(String name)Gets anArgumentbased on its name (argument name).List<Argument>getArguments()Gets the list of defined arguments.StringgetDescription()StringgetName()OptiongetOption(String name)Gets anOptionbased on its name (short name, long name or argument name).List<Option>getOptions()Gets the list of options.intgetPriority()StringgetSummary()booleanisHidden()Checks whether or not the currentCLIinstance is hidden.CommandLineparse(List<String> arguments)Parses the user command line interface and create a newCommandLinecontaining extracting values.CommandLineparse(List<String> arguments, boolean validate)Parses the user command line interface and create a newCommandLinecontaining extracting values.CLIremoveArgument(int index)Removes an argument identified by its index.CLIremoveOption(String name)Removes an option identified by its name.CLIsetArguments(List<Argument> args)Sets the list of arguments.CLIsetDescription(String desc)CLIsetHidden(boolean hidden)Sets whether or not the current instance ofCLImust be hidden.CLIsetName(String name)Sets the name of the CLI.CLIsetOptions(List<Option> options)Sets the list of arguments.CLIsetPriority(int priority)Sets the priority of the CLI.CLIsetSummary(String summary)Sets the summary of the CLI.CLIusage(StringBuilder builder)Generates the usage / help of the currentCLI.CLIusage(StringBuilder builder, String prefix)Generates the usage / help of the currentCLI.
-
-
-
Method Detail
-
create
static CLI create(String name)
Creates an instance ofCLIusing the default implementation.- Parameters:
name- the name of the CLI (must not benull)- Returns:
- the created instance of
CLI
-
create
static CLI create(Class<?> clazz)
Creates an instance ofCLIfrom the given Java class. It instantiates theCLIobject from the annotations used in the class.- Parameters:
clazz- the annotated class- Returns:
- the created instance of
CLI
-
parse
CommandLine parse(List<String> arguments)
Parses the user command line interface and create a newCommandLinecontaining extracting values.- Parameters:
arguments- the arguments- Returns:
- the creates command line
-
parse
CommandLine parse(List<String> arguments, boolean validate)
Parses the user command line interface and create a newCommandLinecontaining extracting values.- Parameters:
arguments- the argumentsvalidate- enable / disable parsing validation- Returns:
- the creates command line
-
getName
String getName()
- Returns:
- the CLI name.
-
setName
CLI setName(String name)
Sets the name of the CLI.- Parameters:
name- the name- Returns:
- the current
CLIinstance
-
getDescription
String getDescription()
- Returns:
- the CLI description.
-
getSummary
String getSummary()
- Returns:
- the CLI summary.
-
setSummary
CLI setSummary(String summary)
Sets the summary of the CLI.- Parameters:
summary- the summary- Returns:
- the current
CLIinstance
-
isHidden
boolean isHidden()
Checks whether or not the currentCLIinstance is hidden.- Returns:
trueif the currentCLIis hidden, {@link false} otherwise
-
setHidden
CLI setHidden(boolean hidden)
Sets whether or not the current instance ofCLImust be hidden. Hidden CLI are not listed when displaying usages / help messages. In other words, hidden commands are for power user.- Parameters:
hidden- enables or disables the hidden aspect of the CI- Returns:
- the current
CLIinstance
-
getOptions
List<Option> getOptions()
Gets the list of options.- Returns:
- the list of options, empty if none.
-
addOption
CLI addOption(Option option)
Adds an option.- Parameters:
option- the option, must not benull.- Returns:
- the current
CLIinstance
-
addOptions
CLI addOptions(List<Option> options)
Adds a set of options. UnlikesetOptions(List)}, this method does not remove the existing options. The given list is appended to the existing list.- Parameters:
options- the options, must not benull- Returns:
- the current
CLIinstance
-
setOptions
CLI setOptions(List<Option> options)
Sets the list of arguments.- Parameters:
options- the list of options, must not benull- Returns:
- the current
CLIinstance
-
getArguments
List<Argument> getArguments()
Gets the list of defined arguments.- Returns:
- the list of argument, empty if none.
-
addArgument
CLI addArgument(Argument arg)
Adds an argument.- Parameters:
arg- the argument, must not benull- Returns:
- the current
CLIinstance
-
addArguments
CLI addArguments(List<Argument> args)
Adds a set of arguments. UnlikesetArguments(List), this method does not remove the existing arguments. The given list is appended to the existing list.- Parameters:
args- the arguments, must not benull- Returns:
- the current
CLIinstance
-
setArguments
CLI setArguments(List<Argument> args)
Sets the list of arguments.- Parameters:
args- the list of arguments, must not benull- Returns:
- the current
CLIinstance
-
getOption
Option getOption(String name)
Gets anOptionbased on its name (short name, long name or argument name).- Parameters:
name- the name, must not benull- Returns:
- the
Option,nullif not found
-
getArgument
Argument getArgument(String name)
Gets anArgumentbased on its name (argument name).- Parameters:
name- the name of the argument, must not benull- Returns:
- the
Argument,nullif not found.
-
getArgument
Argument getArgument(int index)
Gets anArgumentbased on its index.- Parameters:
index- the index, must be positive or zero.- Returns:
- the
Argument,nullif not found.
-
removeOption
CLI removeOption(String name)
Removes an option identified by its name. This method does nothing if the option cannot be found.- Parameters:
name- the option name- Returns:
- the current
CLIinstance
-
removeArgument
CLI removeArgument(int index)
Removes an argument identified by its index. This method does nothing if the argument cannot be found.- Parameters:
index- the argument index- Returns:
- the current
CLIinstance
-
usage
CLI usage(StringBuilder builder)
Generates the usage / help of the currentCLI.- Parameters:
builder- the string builder in which the help is going to be printed- Returns:
- the current
CLIinstance
-
usage
CLI usage(StringBuilder builder, String prefix)
Generates the usage / help of the currentCLI.- Parameters:
builder- the string builder in which the help is going to be printedprefix- an optional prefix- Returns:
- the current
CLIinstance
-
getPriority
int getPriority()
- Returns:
- the CLI priority.
-
-