Descripción
Create a Picocli CLI with subcommands
File Template: ✅
Prefix
picocli:subcmds
Scopes
java
Snippet de código
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
@Command(name = "${1:cli}", mixinStandardHelpOptions = true, subcommands = {StartCommand.class, StopCommand.class}, description = "${2:Main CLI group}")
public class ${1:CliCommand} implements Runnable {
@Override
public void run() {
// No action for the main group
}
public static void main(String[] args) {
int exitCode = new CommandLine(new ${1:CliCommand}()).execute(args);
System.exit(exitCode);
}
}
@Command(name = "start", description = "Start the service")
class StartCommand implements Runnable {
@Override
public void run() {
System.out.println("Service started");
}
}
@Command(name = "stop", description = "Stop the service")
class StopCommand implements Runnable {
@Override
public void run() {
System.out.println("Service stopped");
}
}