diff --git a/Readme.md b/Readme.md index 22c2dc60e..0ecc298b3 100644 --- a/Readme.md +++ b/Readme.md @@ -981,8 +981,8 @@ program -b subcommand program subcommand -b ``` -By default options are recognised before and after command-arguments. To only process options that come -before the command-arguments, use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program +By default, options are recognised before and after command-arguments. To only process options that come +before the command-arguments (and before any unknown options), use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program without needing to use `--` to end the option processing. To use pass through options in a subcommand, the program needs to enable positional options. diff --git a/lib/command.js b/lib/command.js index 590a271dd..860750eca 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1536,6 +1536,9 @@ Expecting one of '${allowedValues.join("', '")}'`); } // If using passThroughOptions, stop processing options 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, + // - or it is off and so an error will be thrown anyway since no subcommand was found that could reprocess the option. if (this._passThroughOptions) { dest.push(arg); if (args.length > 0) dest.push(...args);