0

有没有办法使用 CommonsCLI 创建一对组,当且仅当使用来自另一个组的项目时才能使用其中一个组?(即两者或都不是)

例如,给定选项选择...

-foo       Enable foo. Must enable either bar or baz, cannot (for obvious reasons) be combined with moo.
-moo       Enable moo. Must enable either bar or baz, cannot (for obvious reasons) be combined with foo.
-bar       Set foo or moo mode to foobar or moobar. Cannot be used without foo or moo modes. Cannot be combined with baz.
-baz       Set foo or moo mode to foobaz or moobaz. Cannot be used without foo or moo modes. Cannot be combined with bar.

这给出了......的有效模式

-foo -bar
-foo -baz
-moo -bar
-moo -baz
<None>

和...的无效模式

-foo -moo [-bar / -baz / None]
-bar -baz [-foo / -moo / None]
-bar
-baz
-foo
-moo
4

1 回答 1

0

我不认为 commons-cli 可以做到这一点,您需要在通过 cli 解析后自己进行一些检查,例如

CommandLine cmd = parser.parse( options, args);
if(cmd.hasOption("foo") && cmd.hasOption("moo")) {
    throw new IOException("invalidoptions");
}
...
于 2017-06-15T07:07:35.273 回答