@Retention(value=RUNTIME) @Target(value={FIELD,PARAMETER}) public static @interface CommandLine.Mixin
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:
@Command(name="HelloWorld")
class HelloWorld implements Runnable {
// adds the --help and --version options to this command
@Mixin
private HelpOptions options = 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;
}
public abstract String name
CommandSpec.
If not specified the name of the annotated field is used.