'Apache Commons CLI: no exception thrown after passing illegal arguments to options
My problem is that I don't see an any exception thrown when an option that should accept no argument is given an argument.
Just standard setup, straight from the documentation
Options options = new Options();
CommandLineParser parser = new DefaultParser();
CommandLine cmd;
option:
Option op = Option.builder("op")
.longOpt("op")
.hasArg(false)
.desc("bla")
.build();
options.addOption(op);
try-catch:
try {
cmd = parser.parse(options, args);
if (cmd.hasOption("op") { //do something }
} catch (ParseException | IllegalArgumentException exp) {
System.err.println(exp.getMessage());
System.exit(0);
}
I've tried every method that seems relevant provided in the Option.Builder class(link), but none of them throws an exception at -op with an argument, say, -op hello
Is there an exception class that handles illegal arguments of options in Apache Commons CLI or do we have to manually do so? (then what's the point of having a method like hasArg(boolean hasArg)? )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
