Skip to content

Commit

Permalink
tfexec: move optional positional argument to init cmd; as flags prece…
Browse files Browse the repository at this point in the history
…de 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.
  • Loading branch information
bschaatsbergen committed Oct 6, 2024
1 parent 1589e33 commit cb6532b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tfexec/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit cb6532b

Please sign in to comment.