@Command(name = "hello", description = "Prints a greeting message")
public class HelloCommand {
@Option(name = "-n", description = "Set the name for the greeting")
private String name;
public void execute() {
if (name != null) {
System.out.println("Hello, " + name + "!");
} else {
System.out.println("Hello, world!");
}
}
}
public static void main(String[] args) {
CommandLineParser parser = new CommandLineParser();
try {
HelloCommand helloCommand = new HelloCommand();
parser.parse(helloCommand, args);
helloCommand.execute();
} catch (CommandLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
}
}