I used to work with Apache Commons Cli 1.2. I wanted the parser to ignore arguments if they are unknown (not added to an Options-Object).
Example (pseudocode):
Options specialOptions;
specialOptions.addOption(null, "help", false, "shows help");
specialOptions.addOption(null, "version", false, "show version");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args); //no third argument, since i dont want the program to stop parsing.
// run program with args: --help --unknown --version
// program shall parse --help AND --version, but ignore --unknown
I used this the solution by Pascal Schäfer: Can Apache Commons CLI options parser ignore unknown command-line options?
This worked fine for me on 1.2, and it works fine on 1.3.1 as well. But its deprecated. The parser I used got replaced by the DefaultParser
. I looked up the functionalities, but there is no such method processOptions
.
I really would like to use code that is not going to be deleted in later releases. Does anyone have an idea how to solve this problem?