Skip to content

Commit

Permalink
Use canPrompt
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Aug 10, 2023
1 parent 4b07598 commit 1d19261
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/cli/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func generateTerraformCmdRun(cli *cli, inputs *terraformInputs) func(cmd *cobra.
return err
}

if !checkOutputDirectoryIsEmpty(cli, inputs.OutputDIR) {
if !checkOutputDirectoryIsEmpty(cli, cmd, inputs.OutputDIR) {
return nil
}

Expand Down Expand Up @@ -279,7 +279,7 @@ func terraformProviderCredentialsAreAvailable() bool {
return (domain != "" && clientID != "" && clientSecret != "") || (domain != "" && apiToken != "")
}

func checkOutputDirectoryIsEmpty(cli *cli, outputDIR string) bool {
func checkOutputDirectoryIsEmpty(cli *cli, cmd *cobra.Command, outputDIR string) bool {
_, err := os.Stat(outputDIR)
if os.IsNotExist(err) {
return true
Expand All @@ -298,7 +298,7 @@ func checkOutputDirectoryIsEmpty(cli *cli, outputDIR string) bool {
outputDIR,
)

if !cli.force && !cli.noInput {
if !cli.force && canPrompt(cmd) {
if confirmed := prompt.Confirm("Are you sure you want to proceed?"); !confirmed {
return false
}
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"text/template"

"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -266,12 +267,12 @@ func TestCheckOutputDirectoryIsEmpty(t *testing.T) {
t.Run("it returns true if the directory is empty", func(t *testing.T) {
tempDIR := t.TempDir()

isEmpty := checkOutputDirectoryIsEmpty(&cli{}, tempDIR)
isEmpty := checkOutputDirectoryIsEmpty(&cli{}, &cobra.Command{}, tempDIR)
assert.True(t, isEmpty)
})

t.Run("it returns true if the directory doesn't exist", func(t *testing.T) {
isEmpty := checkOutputDirectoryIsEmpty(&cli{}, "")
isEmpty := checkOutputDirectoryIsEmpty(&cli{}, &cobra.Command{}, "")
assert.True(t, isEmpty)
})

Expand All @@ -295,7 +296,7 @@ func TestCheckOutputDirectoryIsEmpty(t *testing.T) {
noInput: true,
}

isEmpty := checkOutputDirectoryIsEmpty(cli, tempDIR)
isEmpty := checkOutputDirectoryIsEmpty(cli, &cobra.Command{}, tempDIR)
assert.True(t, isEmpty)
assert.Contains(t, stdout.String(), "Proceeding will overwrite the auth0_main.tf, auth0_import.tf and auth0_generated.tf files.")
})
Expand Down

0 comments on commit 1d19261

Please sign in to comment.