Skip to content

Commit

Permalink
Inherit _asyncParsing. Do not unset it and _shouldAwait
Browse files Browse the repository at this point in the history
This is in accordance with how other properties containing information
about the last parse call such as args & processedArgs do not get unset.
Consistency in how repeated parse calls are handled could be improved by
resolving tj#1916.
  • Loading branch information
aweebit committed Jul 26, 2023
1 parent fb48134 commit c34a839
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,15 +926,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
this._asyncParsing = false;
this._setShouldAwait();

try {
const userArgs = this._prepareUserArgs(argv, parseOptions);
this._parseCommand([], userArgs);
const userArgs = this._prepareUserArgs(argv, parseOptions);
this._parseCommand([], userArgs);

return this;
} finally {
this._asyncParsing = undefined;
this._shouldAwait = undefined;
}
return this;
}

/**
Expand All @@ -960,15 +955,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
this._asyncParsing = true;
this._setShouldAwait();

try {
const userArgs = this._prepareUserArgs(argv, parseOptions);
await this._parseCommand([], userArgs);
const userArgs = this._prepareUserArgs(argv, parseOptions);
await this._parseCommand([], userArgs);

return this;
} finally {
this._asyncParsing = undefined;
this._shouldAwait = undefined;
}
return this;
}

/**
Expand All @@ -991,9 +981,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
*/

_setShouldAwait() {
for (let cmd = this; this._shouldAwait === undefined; cmd = cmd.parent) {
this._shouldAwait = cmd._await ?? cmd._asyncParsing;
}
this._shouldAwait = undefined;
let cmd = this;
do {
this._shouldAwait = cmd._await;
cmd = cmd.parent;
} while (this._shouldAwait === undefined && cmd);
this._shouldAwait ??= this._asyncParsing;
}

/**
Expand Down Expand Up @@ -1199,6 +1193,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
_dispatchSubcommand(commandName, operands, unknown) {
const subCommand = this._findCommand(commandName);
if (!subCommand) this.help({ error: true });
subCommand._asyncParsing = this._asyncParsing;

let hookResult;
hookResult = this._chainOrCallSubCommandHook(hookResult, subCommand, 'preSubcommand');
Expand Down

0 comments on commit c34a839

Please sign in to comment.