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

Support showing global options in help #1828

Merged
merged 6 commits into from Dec 7, 2022

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Dec 3, 2022

Pull Request

Commander has long supported options at both the program level and in subcommands, but using both at once was a little subtle for both the author and the end-user.

Problem

In the Help you can't see all the options at once for a subcommand when the program has global options.

See: #1078 #1689

The global options poll has continued accumulating votes for displaying global options after the poll was closed. #1551 (comment)

Solution

Add help configuration to show the global options. This is off by default so can go in a feature version without changing behaviour of executing programs.

The global options are included in the padding calculations and are optional sorted.

The global options are shown in a separate section. This is the layout that was shown in #1551 (comment)).

Using the updated example file:

$ node examples/global-options-nested.js sub --help
Usage: global-options-nested sub [options]

Options:
  -l, --local
  -h, --help    display help for command

Global Options:
  -g, --global

ChangeLog

  • added: showGlobalOptions to .configureHelp{}

@shadowspawn shadowspawn marked this pull request as draft December 3, 2022 06:33
@shadowspawn shadowspawn marked this pull request as ready for review December 3, 2022 07:01
Copy link
Collaborator

@abetomo abetomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Dec 7, 2022
@shadowspawn shadowspawn merged commit 0ae5b2f into tj:develop Dec 7, 2022
@shadowspawn shadowspawn deleted the feature/global-options-in-help branch December 7, 2022 19:52
@shadowspawn
Copy link
Collaborator Author

Released with Commander v9.5.0

@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jan 7, 2023
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 this pull request may close these issues.

None yet

2 participants