From 5641de51f9598e96cc1b3ca7794f9ca12eff3f04 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Mon, 13 Feb 2023 10:02:40 -0700 Subject: [PATCH] fix: pass command instance to parse context (#628) --- src/parser/parse.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/parser/parse.ts b/src/parser/parse.ts index 72fbd4f1d..09064fd29 100644 --- a/src/parser/parse.ts +++ b/src/parser/parse.ts @@ -284,11 +284,16 @@ export class Parser const tokens = this._argTokens let stdinRead = false + const ctx = this.context for (const [name, arg] of Object.entries(this.input.args)) { const token = tokens.find(t => t.arg === name) + ctx.token = token if (token) { if (arg.options && !arg.options.includes(token.input)) { throw new ArgInvalidOptionError(arg, token.input) } - const parsed = await arg.parse(token.input, {...this.context, token}, arg) + const parsed = await arg.parse(token.input, ctx, arg) argv.push(parsed) args[token.arg] = parsed } else if (!arg.ignoreStdin && !stdinRead) { let stdin = await readStdin() if (stdin) { stdin = stdin.trim() - const parsed = await arg.parse(stdin, {...this.context, token}, arg) + const parsed = await arg.parse(stdin, ctx, arg) argv.push(parsed) args[name] = parsed }