Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require one argument only in Apache Commons CLI?

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!

like image 678
Rory Avatar asked Jul 20 '12 14:07

Rory


1 Answers

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...)

like image 137
Jon Skeet Avatar answered Oct 30 '22 02:10

Jon Skeet