Skip to content

Commit

Permalink
Position _parseArg() better
Browse files Browse the repository at this point in the history
  • Loading branch information
aweebit committed Jul 26, 2023
1 parent e66eda5 commit fb48134
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,43 +284,6 @@ class Command extends EventEmitter {
return this;
}

/**
* @param {Argument|Option} target
* @return {boolean}
* @api private
*/

_shouldChainArgParserCalls(target) {
return target.chained || (target.chained === undefined && this._asyncParsing);
}

/**
* Internal implementation shared by ._processArguments() and option and optionEnv event listeners.
*
* @param {Argument|Option} target
* @param {*} value
* @param {*} previous
* @param {Function} handleError
* @return {*}
* @api private
*/

_parseArg(target, value, previous, handleError) {
const handleThenableError = this._shouldAwait ? handleError : undefined;

try {
if (this._shouldChainArgParserCalls(target)) {
return this._chainOrCall(previous, (resolvedPrevious) => (
parseArg(target, value, resolvedPrevious, handleThenableError)
));
}

return parseArg(target, value, previous, handleThenableError);
} catch (err) {
handleError(err);
}
}

/**
* Factory routine to create a new unattached argument.
*
Expand Down Expand Up @@ -1412,6 +1375,43 @@ Expecting one of '${allowedValues.join("', '")}'`);
return result;
}

/**
* @param {Argument|Option} target
* @return {boolean}
* @api private
*/

_shouldChainArgParserCalls(target) {
return target.chained || (target.chained === undefined && this._asyncParsing);
}

/**
* Internal implementation shared by ._processArguments() and option and optionEnv event listeners.
*
* @param {Argument|Option} target
* @param {*} value
* @param {*} previous
* @param {Function} handleError
* @return {*}
* @api private
*/

_parseArg(target, value, previous, handleError) {
const handleThenableError = this._shouldAwait ? handleError : undefined;

try {
if (this._shouldChainArgParserCalls(target)) {
return this._chainOrCall(previous, (resolvedPrevious) => (
parseArg(target, value, resolvedPrevious, handleThenableError)
));
}

return parseArg(target, value, previous, handleThenableError);
} catch (err) {
handleError(err);
}
}

/**
* Process arguments in context of this command.
* Returns action result, in case it is a promise.
Expand Down

0 comments on commit fb48134

Please sign in to comment.