Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat Request: Sort help commands alphabetically #625

Closed
ablankenship10 opened this issue Apr 30, 2017 · 7 comments
Closed

Feat Request: Sort help commands alphabetically #625

ablankenship10 opened this issue Apr 30, 2017 · 7 comments

Comments

@ablankenship10
Copy link

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];
});
tedivm added a commit to tedivm/commander.js that referenced this issue Nov 26, 2017
@tedivm
Copy link

tedivm commented Nov 26, 2017

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

@shadowspawn
Copy link
Collaborator

#910 is the same request, but for options

@shadowspawn
Copy link
Collaborator

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?

@tedivm
Copy link

tedivm commented May 13, 2019

I wouldn't even mind it being opt in to preserve backwards compatibility.

@shadowspawn
Copy link
Collaborator

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.

@shadowspawn
Copy link
Collaborator

Commander 7 allows:

program.configureHelp({
   sortSubcommands: true
});

@carmanchris31
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants