Require one argument only in Apache Commons CLI?

Viewed 2556

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!

1 Answers
Related