Skip to content

Commit

Permalink
Removing redundant struct (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Dec 14, 2023
1 parent d64e88d commit ddc87e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
6 changes: 3 additions & 3 deletions tfexec/internal/e2etest/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func TestShowFloat64(t *testing.T) {
t.Fatalf("error running Apply in test directory: %s", err)
}

actual, err := tf.Show(context.Background(), tfexec.JSONNumber(tfexec.UseJSONNumber{UseJSONNumber: false}))
actual, err := tf.Show(context.Background(), tfexec.JSONNumber(false))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -959,7 +959,7 @@ func TestShowStateFileFloat64(t *testing.T) {
t.Fatalf("error running Apply in test directory: %s", err)
}

actual, err := tf.ShowStateFile(context.Background(), filepath.Join(tf.WorkingDir(), "terraform.tfstate"), tfexec.JSONNumber(tfexec.UseJSONNumber{UseJSONNumber: false}))
actual, err := tf.ShowStateFile(context.Background(), filepath.Join(tf.WorkingDir(), "terraform.tfstate"), tfexec.JSONNumber(false))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1069,7 +1069,7 @@ func TestShowPlanFileBigInt(t *testing.T) {
t.Fatalf("error running Plan in test directory: %s", err)
}

actual, err := tf.ShowPlanFile(context.Background(), filepath.Join(tf.WorkingDir(), "tfplan"), tfexec.JSONNumber(tfexec.UseJSONNumber{UseJSONNumber: true}))
actual, err := tf.ShowPlanFile(context.Background(), filepath.Join(tf.WorkingDir(), "tfplan"), tfexec.JSONNumber(true))
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 4 additions & 8 deletions tfexec/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,13 @@ func GraphPlan(file string) *GraphPlanOption {
return &GraphPlanOption{file}
}

// UseJSONNumber determines how numerical values are handled when JSON is decoded.
type UseJSONNumber struct {
UseJSONNumber bool
useJSONNumber bool
}

type UseJSONNumberOption struct {
useJSONNumber UseJSONNumber
}

func JSONNumber(config UseJSONNumber) *UseJSONNumberOption {
return &UseJSONNumberOption{config}
// JSONNumber determines how numerical values are handled during JSON decoding.
func JSONNumber(useJSONNumber bool) *UseJSONNumber {
return &UseJSONNumber{useJSONNumber}
}

type PlatformOption struct {
Expand Down
22 changes: 11 additions & 11 deletions tfexec/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type showConfig struct {
reattachInfo ReattachInfo
jsonConfig *UseJSONNumber
jsonNumber *UseJSONNumber
}

var defaultShowOptions = showConfig{}
Expand All @@ -23,14 +23,14 @@ type ShowOption interface {
configureShow(*showConfig)
}

func (opt *UseJSONNumberOption) configureShow(conf *showConfig) {
conf.jsonConfig = &opt.useJSONNumber
}

func (opt *ReattachOption) configureShow(conf *showConfig) {
conf.reattachInfo = opt.info
}

func (opt *UseJSONNumber) configureShow(conf *showConfig) {
conf.jsonNumber = opt
}

// Show reads the default state path and outputs the state.
// To read a state or plan file, ShowState or ShowPlan must be used instead.
func (tf *Terraform) Show(ctx context.Context, opts ...ShowOption) (*tfjson.State, error) {
Expand Down Expand Up @@ -59,8 +59,8 @@ func (tf *Terraform) Show(ctx context.Context, opts ...ShowOption) (*tfjson.Stat
var ret tfjson.State
ret.UseJSONNumber(true)

if c.jsonConfig != nil {
ret.UseJSONNumber(c.jsonConfig.UseJSONNumber)
if c.jsonNumber != nil {
ret.UseJSONNumber(c.jsonNumber.useJSONNumber)
}

err = tf.runTerraformCmdJSON(ctx, showCmd, &ret)
Expand Down Expand Up @@ -107,8 +107,8 @@ func (tf *Terraform) ShowStateFile(ctx context.Context, statePath string, opts .
var ret tfjson.State
ret.UseJSONNumber(true)

if c.jsonConfig != nil {
ret.UseJSONNumber(c.jsonConfig.UseJSONNumber)
if c.jsonNumber != nil {
ret.UseJSONNumber(c.jsonNumber.useJSONNumber)
}

err = tf.runTerraformCmdJSON(ctx, showCmd, &ret)
Expand Down Expand Up @@ -154,8 +154,8 @@ func (tf *Terraform) ShowPlanFile(ctx context.Context, planPath string, opts ...

var ret tfjson.Plan

if c.jsonConfig != nil {
ret.UseJSONNumber(c.jsonConfig.UseJSONNumber)
if c.jsonNumber != nil {
ret.UseJSONNumber(c.jsonNumber.useJSONNumber)
}

err = tf.runTerraformCmdJSON(ctx, showCmd, &ret)
Expand Down

0 comments on commit ddc87e4

Please sign in to comment.