From a12f5bec4ffa02fa84b3b67d746c616f0efb2130 Mon Sep 17 00:00:00 2001 From: Wee Bit Date: Fri, 4 Aug 2023 03:36:38 +0300 Subject: [PATCH] Run help from default command's parent only if help option is first --- lib/command.js | 5 +---- lib/option.js | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/command.js b/lib/command.js index 131a145ac..17c493bd8 100644 --- a/lib/command.js +++ b/lib/command.js @@ -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); diff --git a/lib/option.js b/lib/option.js index d61fc5f2f..ef23e43f5 100644 --- a/lib/option.js +++ b/lib/option.js @@ -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); } /**