From eae6c5f792cf46bb67d585ff8cca757369944260 Mon Sep 17 00:00:00 2001 From: Wee Bit Date: Fri, 4 Aug 2023 16:10:54 +0300 Subject: [PATCH] Make passThroughOptions continue processing at unknown options So that the help option is correctly consumed. --- lib/command.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/command.js b/lib/command.js index 2634596ad..6fb0e6d17 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1557,13 +1557,14 @@ Expecting one of '${allowedValues.join("', '")}'`); } } - // An unknown option means further arguments also classified as unknown so can be reprocessed by subcommands. if (maybeOption(arg)) { + // An unknown option means further arguments also classified as unknown so can be reprocessed by subcommands. dest = unknown; - } - - // If using passThroughOptions, stop processing options at first command-argument / unknown option. - if (this._passThroughOptions) { + } else if (this._passThroughOptions) { + // If using passThroughOptions, stop processing options at first command-argument. + // Do not stop at unknown option + // - so that known options after it and before a subcommand / command-argument are consumed by the parent command (including the help option); + // - and because that is simply not what passThroughOptions is supposed to do. dest.push(arg, ...args); break; }