public static class NonDefaultCommand { @Option(names = {"-t", "--timeout"}) private long timeout; public NonDefaultCommand(int i) {} } public static class MyFactory implements CommandLine.IFactory {
static class MixMeIn { @Option(names = {"-a", "--alpha"}, description = "option from mixin") private int alpha; @Parameters(description = "parameters from mixin") File[] files; } }
@Command public static class ExampleMixin { @Option(names = "-l") int length; }
static // tag::Git[] // tag::Git-declaration[] @Command(name = "git", mixinStandardHelpOptions = true, version = "subcommand demo 3.0", description = "Git is a fast, scalable, distributed revision control " + "system with an unusually rich command set that provides both " + "high-level operations and full access to internals.", commandListHeading = "%nCommands:%n%nThe most commonly used git commands are:%n") class Git { // end::Git-declaration[] @Option(names = "--git-dir", description = "Set the path to the repository") File gitDir; } // end::Git[]
/** * Helper class encapsulating the command line options and positional parameters. */ @Command(name = "java com.puppycrawl.tools.checkstyle.JavadocPropertiesGenerator", mixinStandardHelpOptions = true) private static class CliOptions { /** * The command line option to specify the output file. */ @Option(names = "--destfile", required = true, description = "The output file.") private File outputFile; /** * The command line positional parameter to specify the input file. */ @Parameters(index = "0", description = "The input file.") private File inputFile; } }
@Command public void doit(@Mixin CommonOption commonOptionParam, @Option(names = "-z") int z, @Parameters String arg0, String arg1) {}
@Command(footer = "Common footer") public class CommonOption { @Option(names = "-x", description = "reusable option you want in many commands") int x; }
@Option(names = "--raptor") void setRaptorFences(final String value) { throw new ParameterException(spec.commandLine(), "RAPTOR error"); } }
@Option(names = "-d", description = "Default: ${DEFAULT-VALUE}", defaultValue = "Annotated setter default value") void setString(String val) { stringForSetterDefault = val; } }
@Command(name = "top", subcommands = Sub.class) static class Top implements Runnable { @Option(names = {"-d", "--directory"}, description = "this option applies to all subcommands") private File baseDirectory; int result; public void run() { } }
@Command(description = "Second level sub-subcommand 2") public static class Sub2Child2 { @Option(names = {"-u", "--timeUnit"}) private TimeUnit timeUnit; @Option(names = {"-t", "--timeout"}) private long timeout; @Parameters(completionCandidates = Candidates.class, description = "with candidates") String str2; }
@Command(description = "Second level sub-subcommand 1") public static class Sub2Child1 { @Option(names = {"-h", "--host"}, description = "a host") InetAddress host; } @Command(description = "Second level sub-subcommand 2")
@Option(names = "--trex") void setTRexFences(final String value) { throw new ParameterException(spec.commandLine(), "TREX error"); } }
@Option(names = "--minimum") public void setMinimum(int min) { if (min < 0) { throw new ParameterException(spec.commandLine(), "Minimum must be a positive integer"); } minimum = min; }
/** * This is the main container which will be populated by picocli with values * from the arguments. */ private static class Options { @Option(names = { "-v", "--verbose" }) private boolean verbose = false; public boolean isVerbose() { return verbose; } } }
@Command(description = "First level subcommand 1") public static class Sub1 { @Option(names = "--num", description = "a number") double number; @Option(names = "--str", description = "a String") String str; @Option(names = "--candidates", completionCandidates = Candidates.class, description = "with candidates") String str2; } @Command(description = "First level subcommand 2")