Either by default or through an option, the help text commands should be sorted alphabetically.
I can submit a PR if adding this line around here is sufficient. I'm not aware of any other usecases where this may cause a problem unless people are using weird characters in their command names. Works on my end anyway.
commands.sort(function (a, b) {
return a[0] > b[0];
});
You can also do this in your own code without needing any upstream changes by putting this before your program.parse(process.argv) call-
program.commands.sort((a, b) => a._name.localeCompare(b._name))
I think having commands sorted is a good default, but am concerned how many users over the years have carefully created custom orders for their help and would be disappointed by an enforced change.
Do we need to provide an opt-out for sorting?
I wouldn't even mind it being opt in to preserve backwards compatibility.
This issue has not had any activity in over six months. It isn't likely to get acted on due to this report (although it is a reasonable suggestion).
Feel free to open a new issue if it comes up again, with new information and renewed interest.
Thank you for your contributions.
Commander 7 allows:
program.configureHelp({
sortSubcommands: true
});
Commander 7 allows:
program.configureHelp({ sortSubcommands: true });
One caveat: It appears this also sorts the default help command with the rest, whereas using the program.commands.sort() method would leave it at the end of the list.
Most helpful comment
Commander 7 allows: