-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Nested Commands: If the parent command has a description, the nested commands are added on first level instead of 2nd level #2316
Comments
I just found out, using const brew = program.command('brew').description('Brew your drinks'); is producing the expected behaviour: $ node -r ts-node/register src/index.ts
Usage: pm [options] [command]
Options:
-h, --help display help for command
Commands:
brew Brew your drinks
help [command] display help for command
$ node -r ts-node/register src/index.ts brew
Usage: pm brew [options] [command]
Brew your drinks
Options:
-h, --help display help for command
Commands:
tea
coffee
help [command] display help for command It may be helpful to document the limitations of the shorthand syntax with
Or maybe even deprecating this way of setting the description in favor of always using |
Have another look at the example under the Commands section in the README: https://github.com/tj/commander.js/blob/master/Readme.md#commands For legacy reasons, there are two quite different ways of adding commands using program.name('git')
.command('clone <repo>', 'clone repo')
.command('push', 'push changes')
.command('pull', 'pull changes'); If you include just the command name, you are creating a subcommand and the new subcommand is returned for configuring, such as by adding a description using const cloneCommand = program.command('clone')
.argument('<repo>')
.description('clone repo')
.action(repo => doClone(repo)); The two approaches are described further as using an action handler or using a stand-alone executable: |
The confusion between commands with an action handler and ones implemented as stand-alone executable files was more common before the README got updated, but can still cause confusion: #938 |
Thanks for the details. |
The following code
Generates
If you change the line
to
the subcommand will appear on the top-level:
I would have expected that the sub-commands
tea
andcoffee
still appear on the 2nd level.Is this a bug or expected behaviour?
The text was updated successfully, but these errors were encountered: