jbock is a command line parser, which uses the same annotation names as JCommander and picocli. However it does not use reflection. It is an annotation processor that generates a custom parser at compile time. jbock requires Java 11.
Quick start
Create an abstract class, or alternatively a Java interface, and add the @Command
annotation. In this class, each abstract method must be parameterless, and corresponds either to a named option or a positional parameter.
@Command
abstract class DeleteCommand {
/* Path, not Optional<Path>:
* This positional parameter is required (multiplicity = 1).
*/
@Parameter(index = 0,
description = "A positional parameter.")
abstract Path path();
/* OptionalInt, not int or Integer:
* This named option is optional (multiplicity = 0..1).
*/
@Option(names = {"-v", "--verbosity"},
description = "A named option.")
abstract OptionalInt verbosity();
}
The following two classes will be generated: DeleteCommandParser, DeleteCommand_Impl.
The *Parser
class can be used directly in a main
method:
public static void main(String[] args) {
DeleteCommand command = new DeleteCommandParser().parseOrExit(args);
// ...
}
In addition to parseOrExit
, there is also a basic parse
method with no side effects. Please see the wiki for details.