Reputation: 1825
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!
Upvotes: 6
Views: 2677
Reputation: 1499760
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...)
Upvotes: 10