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

Is there a way to add subcommand options desc to the default help output #1624

Closed
kuncevic opened this issue Oct 15, 2021 · 5 comments
Closed

Comments

@kuncevic
Copy link

kuncevic commented Oct 15, 2021

Current output:

Options:
  -v, --version                 output the version number
  -h, --help                      display help for command

Commands:
  cmd1                     Desc1
  cmd2 [options]           Desc2
  cmd3 [options]           Desc3

So in order to figure out options you have to run another command cmd2 --help which prints the options details.

I am wondering if it is possible to print that options details as a part of the default help output, or something similar to that:

Options:
  -v, --version                 output the version number
  -h, --help                      display help for command

Commands:
  cmd1                     Desc1
  cmd2 [options]           Desc2
         -o1, option1      ODesc2  
  cmd3 [options]           Desc3
         -o2, option2      ODesc3  
@shadowspawn
Copy link
Collaborator

Nice description, thanks.

There is not direct support for adding subcommand options into the program help (top-level command).


To do it yourself, you could subclass/override the Help class.

The shortcut would be to override subcommandDescription, and tack on the options:

subcommandDescription(cmd) {

The full-blown approach with more control would be to override formatHelp to more explicitly extend the lines that do the subcommands:

For subcommands with a lot of options adding the options may be a bit noisy, but I can imagine it working for modest subcommands!

@kuncevic
Copy link
Author

Yeah understood, it is very hard to please each and every use-case.
Thank you for pointing out to the right direction.

It is something that we should not expect to be a part of the default functionality, right?

@shadowspawn shadowspawn changed the title Is there a way to add options desc to the default help output Is there a way to add subcommand options desc to the default help output Oct 15, 2021
@shadowspawn
Copy link
Collaborator

It is something that we should not expect to be a part of the default functionality, right?

Correct. (Not at this time, based on current utility conventions, and current Commander feedback.)

@kuncevic
Copy link
Author

@shadowspawn Oh, just was thinking of this idea, to be able to mark some of the options to be shown this way.
In my use-case I do have a global flag for some options that will install npm package globally rather than locally

Currently

Commands:
install|i [options] [version]   Install a specific version of Angular CLI. By default it will install the latest version

Option 1

Commands:
install|i [options] [version]   Install a specific version of Angular CLI. By default it will install the latest version
                          -g    Install globally

Option 2

Commands:
install|i [-g] [version]   Install a specific version of Angular CLI. By default it will install the latest version

In that case Option 2 makes a lot of sense for such use-case

@kuncevic kuncevic reopened this Oct 19, 2021
@shadowspawn
Copy link
Collaborator

Interesting idea to mark individual options, but I don't this this scales very well.

No further activity in a month. Closing this as resolved.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

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

No branches or pull requests

2 participants