Apache Commons CLI - 在帮助输出中打印尾随args [英] Apache Commons CLI - print trailing args in help output

查看:175
本文介绍了Apache Commons CLI - 在帮助输出中打印尾随args的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Commons CLI 1.2来解析一个命令行,该命令行最后会带有选项和额外的参数。例如: mycmd -d DIR额外的东西

I'm using Apache Commons CLI 1.2 to parse a command line that takes options and extra arguments at the end. Ex: mycmd -d DIR extra stuff

我知道如何使用<获得'额外'和'东西' code> CommandLine.getArgs(),但我不知道如何在我的帮助输出中显示那些额外的参数。当我这样打电话时:

I know how to get 'extra' and 'stuff' using CommandLine.getArgs(), but I don't know how to display those extra arguments in my help output. When I make a call like this:

new HelpFormatter().printHelp("mycmd", opts, true);

我的输出如下:

usage: mycmd -d DIR

没有额外的参数。有人能指出我正确的方向吗?

without the extra arguments. Could someone point me in the right direction?

推荐答案

据我所知,显示这些额外论点的唯一方法是不打印自动生成的用法语句,而是打印如下自定义用法语句:

As far as I can tell the only way to display those extra arguments would be to not print the automatically generated usage statement and instead print a custom usage statement like this:

new HelpFormatter().printHelp("mycmd -d <DIR> extra stuff", opts);

或者

new HelpFormatter().printHelp("mycmd [options] extra stuff", opts);

或者您想格式化您的使用声明。

or however you want to format your usage statement.

这篇关于Apache Commons CLI - 在帮助输出中打印尾随args的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆