Skip to content

Commit

Permalink
Refactor _checkForBrokenPassThrough() to make it instance-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
aweebit authored and abetomo committed Aug 5, 2023
1 parent ec1942d commit ac8db3a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class Command extends EventEmitter {

this.commands.push(cmd);
cmd.parent = this;
this._checkForBrokenPassThrough(cmd, this);
cmd._checkForBrokenPassThrough();

return this;
}
Expand Down Expand Up @@ -737,19 +737,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
*/
passThroughOptions(passThrough = true) {
this._passThroughOptions = !!passThrough;
this._checkForBrokenPassThrough(this, this.parent);
this._checkForBrokenPassThrough();
return this;
}

/**
* @param {Command} command
* @param {Command | null} parent
* @api private
*/

_checkForBrokenPassThrough(command, parent) {
if (parent && command._passThroughOptions && !parent._enablePositionalOptions) {
throw new Error(`passThroughOptions cannot be used for '${command._name}' without turning on enablePositionalOptions for parent command(s)`);
_checkForBrokenPassThrough() {
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
}
}

Expand Down

0 comments on commit ac8db3a

Please sign in to comment.