【问题标题】:Trailing args using Apache commons cli library [duplicate]使用 Apache commons cli 库的尾随 args [重复]
【发布时间】:2011-11-18 23:19:38
【问题描述】:

我在我们的代码库中发现了一个命令行实用程序,作者在其中编写了一个自制命令行解析器,它涉及的代码比实用程序本身更多。我决定将其切换为使用 Apache CLI,一切都差不多了。

该实用程序使用尾随参数,因此它看起来像这样:

util --argA=1 --argB=2 foo blah blarg

其中“foo”、“blah”和“blarg”用作参数。

有没有办法处理这种情况?我宁愿不(也可能无权)更改此实用程序的命令行签名。

【问题讨论】:

  • 忽略 - 我只是偶然发现了 CommandLine 类中的 getArgs() 方法,这似乎正是我想要的。

标签: java command-line-interface apache-commons apache-commons-cli


【解决方案1】:

查看 CommandLine.getArgList() 或 CommandLine.getArgs(),它们都从命令行返回选项未处理的“剩余”项。

详情请见CommandLine javadocs

【讨论】:

猜你喜欢
  • 2016-12-18
  • 1970-01-01
  • 2013-03-08
  • 1970-01-01
  • 2011-06-09
  • 1970-01-01
  • 2022-12-02
  • 2013-03-21
  • 2015-03-05
相关资源
最近更新 更多