I am working with apache-commons-cli for parsing command line arguments in my java program.
Now, I am trying to find a way to exclude displaying some sensitive or debug options from the usage help. I am using HelpFormatter for the help by the way.
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);
This is printing all the options. But I don't want the third option to be printed.
Actual Output:
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
Expected Output:
usage: Test App
-f <arg> First argument
-s <arg> Second argument
This way, the debug arguments will be known only to the people who actual need to know about it for debugging.
Is there a way to disable a specific option from the help output alone. But still parse it just like any other option?
I am using commons-cli-1.3.1.jar by the way.