Commander.js: Feat Request: Sort help commands alphabetically

Created on 30 Apr 2017  路  7Comments  路  Source: tj/commander.js

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];
});

Most helpful comment

Commander 7 allows:

program.configureHelp({
   sortSubcommands: true
});

All 7 comments

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))

910 is the same request, but for options

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

san-templates picture san-templates  路  5Comments

aminch picture aminch  路  3Comments

0505gonzalez picture 0505gonzalez  路  3Comments

youurayy picture youurayy  路  5Comments

jaredpetersen picture jaredpetersen  路  3Comments