Skip to content

Commit f68b865

Browse files
committed
Fix Ask comfirmation while destroying infrastructure
1 parent 5935427 commit f68b865

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

cli/internals/destroy/destroy.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package destroy
33
import (
44
"errors"
55
"path/filepath"
6-
"strings"
76

87
"github.com/AlecAivazis/survey/v2"
98
"github.com/leapfrogtechnology/shift/core/services/storage"
@@ -12,10 +11,10 @@ import (
1211
"github.com/leapfrogtechnology/shift/infrastructure/internals/terraform"
1312
)
1413

15-
func askConfirmation(environment, projectName string) string {
16-
confirmation := ""
17-
prompt := &survey.Input{
18-
Message: "Are you sure you want to destroy " + environment + " environment from " + projectName + " ?(Y/N): ",
14+
func askConfirmation(environment, projectName string) bool {
15+
confirmation := false
16+
prompt := &survey.Confirm{
17+
Message: "Are you sure you want to destroy " + environment + " environment from " + projectName + " ?",
1918
}
2019
survey.AskOne(prompt, &confirmation)
2120

@@ -32,24 +31,22 @@ func Run(environment string) {
3231
exit.Error(errors.New(message+"'"+environment+"'"), "Error")
3332
}
3433

35-
confirmation := askConfirmation(environment, project.Name)
34+
confirm := askConfirmation(environment, project.Name)
3635

37-
if strings.EqualFold(confirmation, "Y") || strings.EqualFold(confirmation, "yes") {
38-
39-
workspaceRoot := "/tmp"
40-
workspaceDir := filepath.Join(workspaceRoot, project.Name, project.Type, environment)
41-
terraformFile := workspaceDir + "/infrastructure.tf"
36+
if !confirm {
37+
const message = "Operation aborted"
38+
exit.Error(errors.New(message), "Cancelled")
39+
}
4240

43-
exists := file.Exists(terraformFile)
41+
workspaceRoot := "/tmp"
42+
workspaceDir := filepath.Join(workspaceRoot, project.Name, project.Type, environment)
43+
terraformFile := workspaceDir + "/infrastructure.tf"
4444

45-
if exists {
46-
terraform.DestroyInfrastructure(workspaceDir)
47-
} else {
48-
terraform.MakeTempAndDestroy(project, environment, workspaceDir)
49-
}
45+
exists := file.Exists(terraformFile)
5046

47+
if exists {
48+
terraform.DestroyInfrastructure(workspaceDir)
5149
} else {
52-
const message = "Operation aborted"
53-
exit.Error(errors.New(message), "Cancelled")
50+
terraform.MakeTempAndDestroy(project, environment, workspaceDir)
5451
}
5552
}

0 commit comments

Comments
 (0)