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,