-
Notifications
You must be signed in to change notification settings - Fork 7
converter
In the DeleteCommand example,
the path
parameter is required,
while verbosity
is optional.
The @Parameter
and @Option
annotations do not have boolean attributes like
required
or optional
.
Instead, the multiplicity is determined by the parameter type.
(option|param) type | Multiplicity | Arity (if option) |
---|---|---|
boolean |
0..1 (optional) |
nullary |
Optional<A> |
0..1 (optional) |
unary |
Optional{Int,Long,Double} |
0..1 (optional) |
unary |
List<A> |
0..* (repeatable) |
unary |
A (exact match) |
1 (required) |
unary |
where A
must be one of the
auto types,
otherwise compilation will fail.
In the DeleteCommand
example, the type of path
is java.nio.file.Path
, which is one of the
auto types, so the last rule applies, making this a required parameter.
The type of verbosity
is OptionalInt
, so the third rule applies,
which makes this an optional option.
The @Option
and @Parameter
annotations also have an optional attribute
converter
, which takes a single value of type Class<?>
.
A converter class must implement Function<String, E>
or Supplier<Function<String, E>>
for some E
.
When the converter attribute is set, then the multiplicity is determined by looking at both the return type and the converter type.
Converter type | (option|param) type | Multiplicity | Arity (if option) |
---|---|---|---|
String -> M
|
Optional<M> |
0..1 (optional) |
unary |
String -> {Integer,Long,Double}
|
Optional{Int,Long,Double} |
0..1 (optional) |
unary |
String -> M
|
List<M> |
0..n (repeatable) |
unary |
String -> M
|
M |
1 (required) |
unary |
String -> {Integer,Float,...}
|
{int,float,...} |
1 (required) |
unary |
When none of these rules apply, compilation will fail.