Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6ZEVHGaYy15HAxRzy
41 lines
1.2 KiB
Java
41 lines
1.2 KiB
Java
//JAVA 25+
|
|
//DEPS info.picocli:picocli:4.7.7
|
|
|
|
import picocli.CommandLine;
|
|
import picocli.CommandLine.Command;
|
|
import picocli.CommandLine.Option;
|
|
import picocli.CommandLine.Parameters;
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
/**
|
|
* A real command line tool in one file: argument parsing, --help and --version for free.
|
|
* The only build file is the //DEPS line above.
|
|
*/
|
|
@Command(name = "greeter", mixinStandardHelpOptions = true, version = "greeter 1.0",
|
|
description = "Greets people, optionally loudly.")
|
|
public class Greeter implements Callable<Integer> {
|
|
|
|
@Parameters(index = "0", description = "Who to greet.")
|
|
String name;
|
|
|
|
@Option(names = {"-l", "--loud"}, description = "Shout the greeting.")
|
|
boolean loud;
|
|
|
|
@Option(names = {"-n", "--times"}, defaultValue = "1", description = "Repeat count (default: ${DEFAULT-VALUE}).")
|
|
int times;
|
|
|
|
@Override
|
|
public Integer call() {
|
|
String msg = "Hello, " + name + "!";
|
|
for (int i = 0; i < times; i++) {
|
|
System.out.println(loud ? msg.toUpperCase() : msg);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
System.exit(new CommandLine(new Greeter()).execute(args));
|
|
}
|
|
}
|