Apache Commons CLI - print trailing args in help output

▼魔方 西西 提交于 2019-12-22 10:44:27

问题


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

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);

I get output like:

usage: mycmd -d DIR

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


回答1:


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);

or this

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

or however you want to format your usage statement.



来源:https://stackoverflow.com/questions/21870997/apache-commons-cli-print-trailing-args-in-help-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!