feat: demo subcommand
This commit is contained in:
@@ -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) {
|
||||
|
||||
15
src/main/java/me/hatter/demo/commands/DemoSubCommand.java
Normal file
15
src/main/java/me/hatter/demo/commands/DemoSubCommand.java
Normal file
@@ -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.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user