Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Commons CLI - print trailing args in help output

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?

like image 659
Jeff French Avatar asked Oct 17 '25 13:10

Jeff French


1 Answers

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.

like image 95
1000000000 Avatar answered Oct 20 '25 04:10

1000000000