简体   繁体   中英

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?

Eg 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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM