Java プログラムでコマンドライン引数を解析するために apache-commons-cli を使用しています。
現在、一部の機密オプションまたはデバッグオプションの表示を使用法ヘルプから除外する方法を見つけようとしています。ちなみに私はHelpFormatter
ヘルプに使用しています。
Option first = Option.builder("f").hasArg().desc("First argument").build();
Option second = Option.builder("s").hasArg().desc("Second argument").build();
Option debug = Option.builder("d").hasArg().desc("Debug argument. Shouldn't be displayed in help").build();
commandOptions.addOption(first).addOption(second).addOption(debug);
HelpFormatter help = new HelpFormatter();
help.printHelp("Test App", commandOptions);
これはすべてのオプションを印刷しています。しかし、3番目のオプションを印刷したくありません。
実際の出力:
usage: Test App
-d <arg> Debug argument. Shouldn't be displayed in help // This shouldn't be displayed.
-f <arg> First argument
-s <arg> Second argument
期待される出力:
usage: Test App
-f <arg> First argument
-s <arg> Second argument
このようにして、デバッグ引数は、デバッグのためにそれについて実際に知る必要がある人だけに知られます。
ヘルプ出力のみから特定のオプションを無効にする方法はありますか。しかし、他のオプションと同じように解析しますか?
ちなみに使っcommons-cli-1.3.1.jar
ています。