Sebastian Nowak Sebastian Nowak - 1 year ago 107
Java Question

Java apache cli arguments order

I'm using following code to display help screen for the user

HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("asd123", buildOptions());

The arguments are printed in lexicographical order. Is there any way to print them in the order they were added?

Answer Source

HelpFormatter supports setting a different Comparator, see the javadoc.

Therefore it should be possible to add a new java.util.Comparator which knows about the intended order and set it for the HelpFormatter via


Then printHelp() should use the order that you provide.

If you cannot do that then the only option I see is to file an enhancement request with commons-cli.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download