From e9922645d74fe3961c4dfc77d782e2f6833aed49 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Tue, 17 Feb 2026 17:18:04 +0100 Subject: [PATCH] use centralized arguments collection in query --- internal/command/query.go | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/internal/command/query.go b/internal/command/query.go index 8d9a52697b..44fa8e1170 100644 --- a/internal/command/query.go +++ b/internal/command/query.go @@ -125,13 +125,20 @@ func (c *QueryCommand) Run(rawArgs []string) int { return 1 } - // Collect variable value and add them to the operation request - diags = diags.Append(c.GatherVariables(opReq, args.Vars)) - if diags.HasErrors() { + loader, err := c.initConfigLoader() + if err != nil { + diags = diags.Append(err) view.Diagnostics(diags) return 1 } + // Collect variable value and add them to the operation request + var varDiags tfdiags.Diagnostics + opReq.Variables, varDiags = args.Vars.CollectValues(func(filename string, src []byte) { + loader.Parser().ForceFileSource(filename, src) + }) + diags = diags.Append(varDiags) + // Before we delegate to the backend, we'll print any warning diagnostics // we've accumulated here, since the backend will start fresh with its own // diagnostics. @@ -185,25 +192,3 @@ func (c *QueryCommand) OperationRequest( return opReq, diags } - -func (c *QueryCommand) GatherVariables(opReq *backendrun.Operation, args *arguments.Vars) tfdiags.Diagnostics { - var diags tfdiags.Diagnostics - - // FIXME the arguments package currently trivially gathers variable related - // arguments in a heterogenous slice, in order to minimize the number of - // code paths gathering variables during the transition to this structure. - // Once all commands that gather variables have been converted to this - // structure, we could move the variable gathering code to the arguments - // package directly, removing this shim layer. - - varArgs := args.All() - items := make([]arguments.FlagNameValue, len(varArgs)) - for i := range varArgs { - items[i].Name = varArgs[i].Name - items[i].Value = varArgs[i].Value - } - c.Meta.variableArgs = arguments.FlagNameValueSlice{Items: &items} - opReq.Variables, diags = c.collectVariableValues() - - return diags -}