@ParentCommand private PantheonCommand parentCommand; // Picocli injects reference to parent command
@ParentCommand private PantheonCommand parentCommand; // Picocli injects reference to parent command
@ParentCommand private BlocksSubCommand parentCommand; // Picocli injects reference to parent command
@ParentCommand private PublicKeySubCommand parentCommand; // Picocli injects reference to parent command
@ParentCommand private PantheonCommand parentCommand; // Picocli injects reference to parent command
@Command(name = "sub") static class Sub implements Runnable { @ParentCommand private Top parent; @Parameters private int count; private int result; public void run() { int multiplier = parent == null ? 0 : parent.baseDirectory.toString().length(); result = multiplier * count; parent.result = result; } } @Test
usageHelpWidth = 80) class App { @ParentCommand Object parent;
/** * A command with some options to demonstrate completion. */ @Command(name = "cmd", mixinStandardHelpOptions = true, version = "1.0", description = "Command with some options to demonstrate TAB-completion" + " (note that enum values also get completed)") static class MyCommand implements Runnable { @Option(names = {"-v", "--verbose"}) private boolean[] verbosity = {}; @Option(names = {"-d", "--duration"}) private int amount; @Option(names = {"-u", "--timeUnit"}) private TimeUnit unit; @ParentCommand CliCommands parent; public void run() { if (verbosity.length > 0) { parent.out.printf("Hi there. You asked for %d %s.%n", amount, unit); } else { parent.out.println("hi!"); } } }
@Command(name = "list") static class List implements Runnable { @ParentCommand private FileUtils parent; @Option(names = {"-r", "--recursive"}, description = "Recursively list subdirectories") private boolean recursive; public void run() { list(new File(parent.baseDirectory, ".")); } private void list(File dir) { System.out.println(dir.getAbsolutePath()); if (dir.isDirectory()) { for (File f : dir.listFiles()) { if (f.isDirectory() && recursive) { list(f); } else { System.out.println(f.getAbsolutePath()); } } } } }
/** * A command with some options to demonstrate completion. */ @Command(name = "cmd", mixinStandardHelpOptions = true, version = "1.0", description = "Command with some options to demonstrate TAB-completion" + " (note that enum values also get completed)") static class MyCommand implements Runnable { @Option(names = {"-v", "--verbose"}) private boolean[] verbosity = {}; @Option(names = {"-d", "--duration"}) private int amount; @Option(names = {"-u", "--timeUnit"}) private TimeUnit unit; @ParentCommand CliCommands parent; public void run() { if (verbosity.length > 0) { parent.out.printf("Hi there. You asked for %d %s.%n", amount, unit); } else { parent.out.println("hi!"); } } }
/** * Command that clears the screen. */ @Command(name = "cls", aliases = "clear", mixinStandardHelpOptions = true, description = "Clears the screen", version = "1.0") static class ClearScreen implements Callable<Void> { @ParentCommand CliCommands parent; public Void call() throws IOException { parent.reader.clearScreen(); return null; } }
/** * Command that clears the screen. */ @Command(name = "cls", aliases = "clear", mixinStandardHelpOptions = true, description = "Clears the screen", version = "1.0") static class ClearScreen implements Callable<Void> { @ParentCommand CliCommands parent; public Void call() throws IOException { parent.reader.clearScreen(); return null; } }
@Command(name = "sub") static class Sub implements Runnable { @ParentCommand private Top parent; @Parameters private int count; private int result; public void run() { int multiplier = parent == null ? 0 : parent.baseDirectory.toString().length(); result = multiplier * count; parent.result = result; } } @Test