import org.apache.commons.cli.*;
public class CommandLineTool {
public static void main(String[] args) {
Options options = new Options();
CommandLineParser parser = new DefaultParser();
try {
CommandLine cmd = parser.parse(options, args);
if (cmd.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
} else if (cmd.hasOption("version")) {
} else {
}
} catch (ParseException e) {
}
}
}
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
public class CommandLineTool implements Runnable {
@Option(names = "-g", description = "Greeting message")
private String greeting;
public static void main(String[] args) {
CommandLine.run(new CommandLineTool(), args);
}
@Override
public void run() {
if (greeting != null) {
System.out.println(greeting);
} else {
System.out.println("Hello, World!");
}
}
}