Class | Description |
---|---|
CLIConfigurator |
Class responsible for defining CLI using annotations and injecting values extracted by the parser.
|
Annotation Type | Description |
---|---|
Argument |
Annotates a setter to be called with the value of a command line argument.
|
ConvertedBy |
Annotates
@Option setters to indicate how the value is converted to the argument type. |
DefaultValue |
Annotation to set a default value to an option.
|
Description |
Annotation used to write the option or command documentation.
|
Hidden | |
Name |
Defines the name of a
CLI . |
Option |
Annotates a setter to be called with the value of a command line option.
|
ParsedAsList |
Annotates a setter to be called with the value of a command line option.
|
Summary |
Annotates a
CLI with summary. |
Option
and Argument
classes are _untyped_,
meaning that the only get String values.
TypedOption
and TypedArgument
let you specify a _type_, so the
(String) raw value is converted to the specified type.
Instead of
Option
and Argument
, use TypedOption
and TypedArgument
in the CLI
definition:
[source,java]
----
examples.cli.TypedCLIExamples#example1
----
Then you can retrieve the converted values as follows:
[source,java]
----
examples.cli.TypedCLIExamples#example2
----
The vert.x CLI is able to convert to classes:
* having a constructor with a single
String
argument, such as File
or JsonObject
* with a static `from` or `fromString` method
* with a static `valueOf` method, such as primitive types and enumeration
In addition, you can implement your own Converter
and instruct the CLI to use
this converter:
[source,java]
----
examples.cli.TypedCLIExamples#example3
----
For booleans, the boolean values are evaluated to true
: `on`, `yes`, `1`, `true`.
If one of your option has an `enum` as type, it computes the set of choices automatically.
=== Using annotations
You can also define your CLI using annotations. Definition is done using annotation on the class and on _setter_
methods:
[source, java]
----
@Name("some-name")
@Summary("some short summary.")
@Description("some long description")
public class AnnotatedCli {
private boolean flag;
private String name;
private String arg;
@Option(shortName = "f", flag = true)
public void setFlag(boolean flag) {
this.flag = flag;
}
@Option(longName = "name")
public void setName(String name) {
this.name = name;
}
@Argument(index = 0)
public void setArg(String arg) {
this.arg = arg;
}
}
----
Once annotated, you can define the CLI
and inject the values using:
[source,java]
----
examples.cli.TypedCLIExamples#example4
----Copyright © 2017. All rights reserved.