2
想要使用Option
(apache.commons.cli)作为命令和子命令。Apache.commons.cli命令行参数
Ex。
- myprogram工作-dryrun
- myprogram工作-update
- myprogram工作-UPDATE -dryrun
什么是做这种方式吗?
试图用简单的程序:
public static void main(String[] args) throws ParseException {
test("job", "-update"); //works fine
test("job", "-dryrun"); //works fine
test("job", "-update", "-dryrun"); // doesn't work
}
public static void test(String... args) throws ParseException {
GnuParser parser = new GnuParser();
Options options = new Options();
OptionGroup option = new OptionGroup();
option.addOption(new Option("dryrun", "dryrun"));
option.addOption(new Option("update", "update"));
options.addOptionGroup(option);
parser.parse(options, args);
}
错误:
test("job", "-update", "-dryrun");
fails with, Exception in thread "main" org.apache.commons.cli.AlreadySelectedException: The option 'dryrun' was specified but an option from this group has already been selected: 'update'