相关疑难解决方法(0)

Apache Commons CLI选项解析器可以忽略未知的命令行选项吗?

我正在编写一个Java应用程序,它接受使用Apache Commons CLI和GnuParser处理的命令行参数.由于没有兴趣进入的原因,我希望它默默地忽略未知的命令行选项而不是抛出ParseException,但我没有看到这样做的方法.我看到GnuParser.parse()上有一个stopAtNonOption布尔选项,但我想要的更像ignoreAtNonOption,它会在遇到未知令牌后继续处理选项.

我可以实现我自己的解析器来完成这个,但我很惊讶没有内置这个功能,所以我想我会在走这条路之前检查一下.

我正在谈论的示例代码:

try {
  CommandLine commandLine = parser.parse(options, args);
  // stopAtNonOption set to true (below) is also not what I want
  // CommandLine commandLine = parser.parse(options, args, true);
} catch (ParseException e) {
  LOG.error("error parsing arguments", e);
  throw new RuntimeException(e);
}
Run Code Online (Sandbox Code Playgroud)

java apache-commons apache-commons-cli

20
推荐指数
2
解决办法
9759
查看次数

标签 统计

apache-commons ×1

apache-commons-cli ×1

java ×1