From e7c790a0340ef2c1a8615166dda13be0bec34980 Mon Sep 17 00:00:00 2001 From: aweebit Date: Sun, 6 Aug 2023 19:52:47 +0300 Subject: [PATCH] Fix implicit default command starting with unknown option Reverts to original conditionals structure so that implicitly invoked default commands behave as if the command name came before the first arg that is not a known option, and not as if it came before the first arg that is not an option (known or unknown) like previously. Fixes pass through and handling of options after the unknown for implicitly invoked default commands. --- lib/command.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/command.js b/lib/command.js index 4a552d231..6e8ce0361 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1531,10 +1531,7 @@ Expecting one of '${allowedValues.join("', '")}'`); // - any other option unknown to this command, // - or a command-argument. - if (maybeOption(arg)) { - // An unknown option means further arguments also classified as unknown so can be reprocessed by subcommands. - dest = unknown; - } else if (!reprocessedBySubcommand) { + if (!reprocessedBySubcommand) { const onlyKnownOptionsSoFar = operands.length === 0 && unknown.length === 0; if (onlyKnownOptionsSoFar) { reprocessedBySubcommand = true; // reset to false later if not entering subcommand @@ -1563,6 +1560,11 @@ Expecting one of '${allowedValues.join("', '")}'`); } } + // An unknown option means further arguments also classified as unknown so can be reprocessed by subcommands. + if (maybeOption(arg)) { + dest = unknown; + } + // If using passThroughOptions, stop processing options (except help) at first command-argument. // The processing is also stopped when an unknown option is encountered because // - either allowUnknownOption is on and so the option is treated as a command-argument,