Skip to content

Commit

Permalink
Improve help for subcommands with an executable handler
Browse files Browse the repository at this point in the history
- Support subcommands with only a short help flag
- Get help flags from the subcommand (enables additional customization)
- Ensures consistency with how help for subcommands without an
executable handler is implemented (preSubcommand hooks are not called)
  • Loading branch information
aweebit committed Aug 13, 2023
1 parent a253ec6 commit 23bb761
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -1096,14 +1096,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
this.help();
}
const subCommand = this._findCommand(subcommandName);
if (subCommand && !subCommand._executableHandler) {
if (!subCommand) {
this.help({ error: true });
} else if (!subCommand._executableHandler) {
subCommand.help();
}

// Fallback to parsing the help flag to invoke the help.
if (this._helpLongFlag) {
return this._dispatchSubcommand(subcommandName, [], [this._helpLongFlag]);
}
this._executeSubCommand(subCommand, [
subCommand._helpLongFlag || subCommand._helpShortFlag
]);
}

/**
Expand Down

0 comments on commit 23bb761

Please sign in to comment.