diff --git a/src/main/java/me/hatter/demo/PicocliCli.java b/src/main/java/me/hatter/demo/PicocliCli.java index 2d8a6ac..1f34620 100644 --- a/src/main/java/me/hatter/demo/PicocliCli.java +++ b/src/main/java/me/hatter/demo/PicocliCli.java @@ -1,32 +1,26 @@ package me.hatter.demo; +import me.hatter.demo.commands.DemoSubCommand; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Option; -import picocli.CommandLine.Parameters; + import java.io.File; @Command(name = "example", mixinStandardHelpOptions = true, - version = "Picocli example 1.0") -public class PicocliCli { + version = "Picocli example 1.0", + subcommands = { + DemoSubCommand.class + }) +public class PicocliCli implements Runnable { @Option(names = {"-v", "--verbose"}, description = "Verbose mode. Helpful for troubleshooting. Multiple -v options increase the verbosity.") private boolean[] verbose = new boolean[0]; - @Parameters(arity = "1..*", paramLabel = "FILE", description = "File(s) to process.") - private File[] inputFiles; - public void run() { - if (verbose.length > 0) { - System.out.println(inputFiles.length + " files to process..."); - } - if (verbose.length > 1) { - for (File f : inputFiles) { - System.out.println(f.getAbsolutePath()); - } - } + System.out.println("Use --help for help"); } public static void main(String[] args) { diff --git a/src/main/java/me/hatter/demo/commands/DemoSubCommand.java b/src/main/java/me/hatter/demo/commands/DemoSubCommand.java new file mode 100644 index 0000000..647ce20 --- /dev/null +++ b/src/main/java/me/hatter/demo/commands/DemoSubCommand.java @@ -0,0 +1,15 @@ +package me.hatter.demo.commands; + +import picocli.CommandLine; +import picocli.CommandLine.Option; + +@CommandLine.Command(name = "demo", description = "Demo subcommand") +public class DemoSubCommand implements Runnable { + @Option(names = {"-h", "--help"}, usageHelp = true, description = "Show this help message and exit.")//, hidden = true) + boolean helpRequested = false; + + @Override + public void run() { + System.out.println("Subcommand demo."); + } +}