From 1b71d09d4de7211ec5a235a459d156cabfe9b333 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 6 Oct 2024 18:21:37 +0200 Subject: [PATCH] tfexec: move optional positional argument to init cmd; as flags precede positional arguments. Since the optional positional directory argument must follow all flags, as flags precede positional arguments, we append it to the args list only after all flags have been added. Signed-off-by: Bruno Schaatsbergen --- tfexec/init.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tfexec/init.go b/tfexec/init.go index 2ecccac1..ac5eea55 100644 --- a/tfexec/init.go +++ b/tfexec/init.go @@ -157,6 +157,11 @@ func (tf *Terraform) initCmd(ctx context.Context, opts ...InitOption) (*exec.Cmd return nil, err } + // Optional positional argument; must be last as flags precede positional arguments. + if c.dir != "" { + args = append(args, c.dir) + } + return tf.buildInitCmd(ctx, c, args) } @@ -175,6 +180,11 @@ func (tf *Terraform) initJSONCmd(ctx context.Context, opts ...InitOption) (*exec args = append(args, "-json") + // Optional positional argument; must be last as flags precede positional arguments. + if c.dir != "" { + args = append(args, c.dir) + } + return tf.buildInitCmd(ctx, c, args) } @@ -228,11 +238,6 @@ func (tf *Terraform) buildInitArgs(ctx context.Context, c initConfig) ([]string, } } - // optional positional argument - if c.dir != "" { - args = append(args, c.dir) - } - return args, nil }