Package nz.org.riskscape.picocli
Annotation Interface CommandLine.Mixin
- Enclosing class:
- CommandLine
Fields annotated with @Mixin
are "expanded" into the current command: @Option
and
@Parameters
in the mixin class are added to the options and positional parameters of this command.
A CommandLine.DuplicateOptionAnnotationsException
is thrown if any of the options in the mixin has the same name as
an option in this command.
The Mixin
annotation provides a way to reuse common options and parameters without subclassing. For example:
class HelloWorld implements Runnable {// adds the --help and --version options to this command @Mixin private HelpOptions = new HelpOptions(); @Option(names = {"-u", "--userName"}, required = true, description = "The user name") String userName; public void run() { System.out.println("Hello, " + userName); }
}
// Common reusable help options. class HelpOptions {
@Option(names = { "-h", "--help"}, usageHelp = true, description = "Display this help and exit") private boolean help; @Option(names = { "-V", "--version"}, versionHelp = true, description = "Display version info and exit") private boolean versionHelp;
}
- Since:
- 3.0
-
Optional Element Summary
-
Element Details
-
name
String nameOptionally specify a name that the mixin object can be retrieved with from theCommandSpec
. If not specified the name of the annotated field is used.- Returns:
- a String to register the mixin object with, or an empty String if the name of the annotated field should be used
- Default:
- ""
-