1080
}
1081
parse(
1083
>
shortCircuit?: object | ParseCallback | boolean,
1084
>
_parseFn?: ParseCallback
1085
>
): Arguments | Promise<Arguments> {
1086
>
argsert(
1087
>
'[string|array] [function|boolean|object] [function]',
1088
>
[args, shortCircuit, _parseFn],
1089
>
arguments.length
1090
>
);
1091
>
this[kFreeze](); // Push current state of parser onto stack.
1092
>
if (typeof args === 'undefined') {
1093
args = this.#processArgs;
1094
}
1096
>
// a context object can optionally be provided, this allows
1097
>
// additional information to be passed to a command handler.
1098
>
if (typeof shortCircuit === 'object') {
1099
this.#parseContext = shortCircuit;
1100
shortCircuit = _parseFn;
1101
}
1103
>
// by providing a function as a second argument to
1104
>
// parse you can capture output that would otherwise
1105
>
// default to printing to stdout/stderr.
1106
>
if (typeof shortCircuit === 'function') {
1107
this.#parseFn = shortCircuit as ParseCallback;
1108
shortCircuit = false;
1109
}
1111
>
// skipping validation, etc.
1112
>
if (!shortCircuit) this.#processArgs = args;
1113
>
1114
>
if (this.#parseFn) this.#exitProcess = false;
1115
>
1116
>
const parsed = this[kRunYargsParserAndExecuteCommands](
1117
>
args,
1118
>
!!shortCircuit
1119
>
);
1120
>
const tmpParsed = this.parsed;
1121
>
this.#completion!.setParsed(this.parsed as DetailedArguments);
1122
>
if (isPromise(parsed)) {
1123
return parsed
1124
.then(argv => {