- Jakarta Commons CLI
- コマンドライン引数をパースしてというCLI(Command Line Interface)
- Options: 受け取れるオプション
- addOptionで受け取れる引数を追加していく
- parser.parse(options, args)とするとパースした結果を得られる
import org.apache.commons.cli.base.*;
final Options options = new Options();
final Option helpOpt = OptionBuilder
.hasArg(false)
.withArgName("help")
.isRequired(false)
.withDescription("このヘルプ")
.withLongOpt("help")
.create(HELP_OPT);
options.addOption(helpOpt);
final CommandLineParser parser = new BasicParser();
final CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
} catch (ParseException e) {
new HelpFormatter().printHelp("homura help", options)
System.exit(1);
}
関連