Skip to content

Commit

Permalink
feat: allow cli.outputHelp to output help message for matched sub-com…
Browse files Browse the repository at this point in the history
…mand
  • Loading branch information
egoist committed Nov 26, 2018
1 parent 1df4f4d commit 4d15c3b
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2,088 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- [cli.parse(argv?)](#cliparseargv)
- [cli.version(version)](#cliversionversion)
- [cli.help(callback?)](#clihelpcallback)
- [cli.outputHelp()](#clioutputhelp)
- [cli.outputHelp(subCommand?)](#clioutputhelpsubcommand)
- [Command Instance](#command-instance)
- [command.option()](#commandoption)
- [command.action(callback)](#commandactioncallback)
Expand Down Expand Up @@ -291,11 +291,11 @@ interface HelpSection {
}
```

#### cli.outputHelp()
#### cli.outputHelp(subCommand?)

- Type: `() => CLI`
- Type: `(subCommand?: boolean) => CLI`

Output help message.
Output help message. Optional `subCommand` argument if you want to output the help message for the matched sub-command instead of the global help message.

### Command Instance

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class CAC extends EventEmitter {
return this
}

outputHelp() {
if (this.matchedCommand) {
outputHelp(subCommand?: boolean) {
if (subCommand && this.matchedCommand) {
this.matchedCommand.outputHelp({
bin: this.bin,
subCommands:
Expand Down Expand Up @@ -177,7 +177,7 @@ class CAC extends EventEmitter {
{ args, options }: ParsedArgv
) {
if (options.help && globalCommand.hasOption('help')) {
return this.outputHelp()
return this.outputHelp(true)
}

if (options.version && globalCommand.hasOption('version')) {
Expand Down
Loading

0 comments on commit 4d15c3b

Please sign in to comment.