Java apache cli arguments order

866 views Asked by At

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?

1

There are 1 answers

2
centic On BEST ANSWER

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

formatter.setOptionComparator(comparator)

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.