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

Help text for subcommand options #905

Closed
jwheare opened this issue Jan 14, 2019 · 11 comments
Closed

Help text for subcommand options #905

jwheare opened this issue Jan 14, 2019 · 11 comments
Assignees
Labels
docs README (or other docs) could be improved
Milestone

Comments

@jwheare
Copy link

jwheare commented Jan 14, 2019

A subcommand can have options with descriptions defined but I can't see how to make them show up in the help text. It just shows:
subcommand [options]

Is it possible to expand this just as the global options are at the top of the help text?

@shadowspawn
Copy link
Collaborator

To see the options for the subcommand:

command subcommand --help

You can also install a Custom help listener for the subcommand to supply additional information about the subcommand to display when its help is requested.

@jwheare
Copy link
Author

jwheare commented Jan 15, 2019

Ah, thanks, would be good to get this documented. Also is there a way to programmatically trigger it? Thinking of a subcommand like:

command help <subcommand>

Would be useful for people familiar with git's help system.

@jwheare
Copy link
Author

jwheare commented Jan 15, 2019

Looks like this is already stubbed but doesn't seem to do anything:

commander.js/index.js

Lines 210 to 212 in 82d0d0a

Command.prototype.addImplicitHelpCommand = function() {
this.command('help [cmd]', 'display help for [cmd]');
};

@shadowspawn
Copy link
Collaborator

The current behaviour is when using a git-style (sub)command, these two are equivalent, and call the (sub)command with --help to display its help:

my-command help foo
my-command foo --help

@shadowspawn shadowspawn added the docs README (or other docs) could be improved label May 28, 2019
@claytongulick
Copy link

I'm running into this as well. Not sure what the correct approach is.

My structure looks like this:
Top command: reporting (this is npm linked)
Sub commands: reporting-datapump, reporting-scheduler (these are all also npm linked bins)
Sub Sub commands: reporting-datapump clean [options] - this has an action handler, and does the work.

So, from what I can tell, there's no way to get what the [options] are from top level help. These combinations fail:

reporting help datapump
reporting datapump --help
reporting help datapump drop
reporting-datapump help
reporting-datapump help drop -- this shows nothing ?!?

This works:
reporting-datapump drop --help
and this:
reporting datapump drop --help

Perhaps this could all be solved by some sort of recursive help option? I.e. optionally navigate all sub commands recursively and aggregate their helps?

It's not a great user interface for the user to have to guess that specific command in order to see the options for the sub-sub-command help.

My expectation, as a user, would be that when I do:
reporting help datapump or reporting datapump --help I would be able to see all of the sub commands and their options.

@shadowspawn
Copy link
Collaborator

Interesting example of npm -l given in #521 (comment)

@shadowspawn shadowspawn self-assigned this Jan 25, 2020
@benjaminadk

This comment has been minimized.

@shadowspawn

This comment has been minimized.

@shadowspawn
Copy link
Collaborator

For original poster, there are related changes in the published pre-release of Commander v5.0.0 (#1163)

  • there is an implicit help command added when there are subcommands
  • the README now includes a short section under "Automated help" covering getting help for a subcommand

@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Feb 1, 2020
@shadowspawn shadowspawn added this to the v5.0.0 milestone Feb 1, 2020
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Mar 14, 2020
@shadowspawn
Copy link
Collaborator

Commander v5.0.0 has been released with improvements to the help command, and to the README.

https://github.com/tj/commander.js/releases/tag/v5.0.0

@shadowspawn
Copy link
Collaborator

Opened poll on possible enhancements to global options: #1551

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs README (or other docs) could be improved
Projects
None yet
Development

No branches or pull requests

4 participants