feat: demo subcommand

This commit is contained in:
2025-05-02 22:28:18 +08:00
parent 66ecce4034
commit bdcd3113b5
2 changed files with 23 additions and 14 deletions

View File

@@ -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) {

View 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.");
}
}