Skip to content

Commit

Permalink
Run help from default command's parent only if help option is first
Browse files Browse the repository at this point in the history
  • Loading branch information
aweebit committed Aug 4, 2023
1 parent 5b93a70 commit a12f5be
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -1272,10 +1272,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
}
if (this._defaultCommandName) {
// Run the help for default command from parent rather than passing to default command
const helpOptionProvided = this._hasHelpOption && unknown.find(
arg => arg === this._helpOption.long || arg === this._helpOption.short
);
if (helpOptionProvided) {
if (this._hasHelpOption && this._helpOption.is(unknown[0])) {
this.emit('option:' + this._helpOption.name());
}
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
Expand Down
4 changes: 2 additions & 2 deletions lib/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ class Option {
/**
* Check if `arg` matches the short or long flag.
*
* @param {string} arg
* @param {string | undefined} arg
* @return {boolean}
* @api private
*/

is(arg) {
return this.short === arg || this.long === arg;
return arg && (this.short === arg || this.long === arg);
}

/**
Expand Down

0 comments on commit a12f5be

Please sign in to comment.