Require one argument only in Apache Commons CLI?

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

eg. I have 2 command line arguments, but should one (no more or no less) be provided? I want either ip or msisdn, but not both, 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!

+5
source share
1 answer

It looks like you need the required OptionGroupone containing two mutually exclusive values Option. Add this parameter group to commandLineOptions.

(This is only a documentation based assumption. I have never used the project itself ...)

+8
source

All Articles