使用Apache commons cli库的尾随args

geo*_*try 4 java command-line-interface apache-commons apache-commons-cli

我在我们的代码库中找到了一个命令行实用程序,其中作者编写了一个自制的命令行解析器,其中包含的代码比实用程序本身更多.我决定将它切换到使用Apache CLI,事情几乎正常.

该实用程序使用尾随args,所以它看起来像这样:

util --argA=1 --argB=2 foo blah blarg
Run Code Online (Sandbox Code Playgroud)

其中"foo","blah"和"blarg"用作参数.

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

cen*_*tic 6

查看CommandLine.getArgList()或CommandLine.getArgs(),它们都返回命令行中未被选项处理的"剩余"项.

有关详细信息,请参阅https://commons.apache.org/proper/commons-cli/apidocs/org/apache/commons/cli/CommandLine.html.