Skip to content

Commit

Permalink
Fix implicit default command starting with unknown option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aweebit committed Aug 6, 2023
1 parent cac1f8a commit e7c790a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e7c790a

Please sign in to comment.