6

I'm just wondering is there any way in the Apache Commons CLI library to specify that exactly one argument must be provided?

E.g. I have 2 command line arguments, but one (no more or no less) must be provided? I want either the ip or msisdn, but not neither and not both:

OptionBuilder.hasArg(true);
OptionBuilder.withDescription("Bla bla");
OptionBuilder.isRequired(false);
commandLineOptions.addOption(OptionBuilder.create("ip"));

OptionBuilder.hasArg(true);
OptionBuilder.withDescription("Bla bla");
OptionBuilder.isRequired(false);
commandLineOptions.addOption(OptionBuilder.create("msisdn"));

Many thanks!

4

1 回答 1

10

It looks like you want a required OptionGroup containing the two mutually-exclusive Option values. Add that option group to commandLineOptions.

(This is only a guess based on the documentation. I've never actually used the project myself...)

于 2012-07-20T14:54:42.143 回答