Skip to content

Commit a12f5be

Browse files
committed
Run help from default command's parent only if help option is first
1 parent 5b93a70 commit a12f5be

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

lib/command.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
12721272
}
12731273
if (this._defaultCommandName) {
12741274
// Run the help for default command from parent rather than passing to default command
1275-
const helpOptionProvided = this._hasHelpOption && unknown.find(
1276-
arg => arg === this._helpOption.long || arg === this._helpOption.short
1277-
);
1278-
if (helpOptionProvided) {
1275+
if (this._hasHelpOption && this._helpOption.is(unknown[0])) {
12791276
this.emit('option:' + this._helpOption.name());
12801277
}
12811278
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);

lib/option.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ class Option {
220220
/**
221221
* Check if `arg` matches the short or long flag.
222222
*
223-
* @param {string} arg
223+
* @param {string | undefined} arg
224224
* @return {boolean}
225225
* @api private
226226
*/
227227

228228
is(arg) {
229-
return this.short === arg || this.long === arg;
229+
return arg && (this.short === arg || this.long === arg);
230230
}
231231

232232
/**

0 commit comments

Comments
 (0)