Skip to content

Commit

Permalink
Fix issue #678: adding an option (--force) allowing to destroy an app…
Browse files Browse the repository at this point in the history
… without confirmation
  • Loading branch information
mrunichs committed Apr 27, 2022
1 parent e541bd2 commit 0b9fb03
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions apps/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/Scalingo/cli/io"
)

func Destroy(appName string) error {
func Destroy(appName string, force bool) error {
var validationName string

c, err := config.ScalingoClient()
Expand All @@ -25,15 +25,21 @@ func Destroy(appName string) error {
return errgo.Mask(err, errgo.Any)
}

fmt.Printf("/!\\ You're going to delete %s, this operation is irreversible.\nTo confirm type the name of the application: ", appName)
validationName, err = bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return errgo.Mask(err, errgo.Any)
}
validationName = strings.Trim(validationName, "\n")
if !force {

fmt.Printf("/!\\ You're going to delete %s, this operation is irreversible.\nTo confirm type the name of the application: ", appName)
validationName, err = bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return errgo.Mask(err, errgo.Any)
}
validationName = strings.Trim(validationName, "\n")

if validationName != appName {
return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, appName)
}
} else {

if validationName != appName {
return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, appName)
validationName = appName
}

err = c.AppsDestroy(appName, validationName)
Expand Down

0 comments on commit 0b9fb03

Please sign in to comment.