Skip to content

Commit 1b71d09

Browse files
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 <git@bschaatsbergen.com>
1 parent 1589e33 commit 1b71d09

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tfexec/init.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func (tf *Terraform) initCmd(ctx context.Context, opts ...InitOption) (*exec.Cmd
157157
return nil, err
158158
}
159159

160+
// Optional positional argument; must be last as flags precede positional arguments.
161+
if c.dir != "" {
162+
args = append(args, c.dir)
163+
}
164+
160165
return tf.buildInitCmd(ctx, c, args)
161166
}
162167

@@ -175,6 +180,11 @@ func (tf *Terraform) initJSONCmd(ctx context.Context, opts ...InitOption) (*exec
175180

176181
args = append(args, "-json")
177182

183+
// Optional positional argument; must be last as flags precede positional arguments.
184+
if c.dir != "" {
185+
args = append(args, c.dir)
186+
}
187+
178188
return tf.buildInitCmd(ctx, c, args)
179189
}
180190

@@ -228,11 +238,6 @@ func (tf *Terraform) buildInitArgs(ctx context.Context, c initConfig) ([]string,
228238
}
229239
}
230240

231-
// optional positional argument
232-
if c.dir != "" {
233-
args = append(args, c.dir)
234-
}
235-
236241
return args, nil
237242
}
238243

0 commit comments

Comments
 (0)