@Command
abstract class DeleteCommand {
@Option(names = {"-v", "--verbosity"},
description = "A named option. The return type reflects optionality.")
abstract OptionalInt verbosity();
@Parameter(
index = 0,
description = {"A required positional parameter. Return type is non-optional.",
"Path is a standard type, so no custom converter is needed."})
abstract Path path();
@Parameter(
index = 1,
description = "An optional positional parameter.")
abstract Optional<Path> anotherPath();
@VarargsParameter(
description = {"A varargs parameter. There can only be one of these.",
"The return type must be List."})
abstract List<Path> morePaths();
@Option(names = "--dry-run",
description = "A nullary option, a.k.a. mode flag. Return type is boolean.")
abstract boolean dryRun();
@Option(names = "-h",
description = "A repeatable option. Return type is List.")
abstract List<String> headers();
@Option(names = "--charset",
description = "Named option with a custom converter",
converter = CharsetConverter.class)
abstract Optional<Charset> charset();
// sample converter class
static class CharsetConverter extends StringConverter<Charset> {
@Override
protected Charset convert(String token) { return StandardCharsets.UTF_8; }
}
}
|