Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clarifications about passThroughOptions handling of unknown options to docs and comments #1942

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down