Sebastian Nowak Sebastian Nowak - 3 months ago 26
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?


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.