Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option (--force) allowing to destroy an app without interactive confirmation #721

Merged
merged 2 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* build(deps): bump github.com/briandowns/spinner from 1.18.0 to 1.18.1
* build(deps): bump github.com/stretchr/testify from 1.7.0 to 1.7.1
* feat(app): add a flag --force to destroy an app without interactive confirmation [#721](https://github.com/Scalingo/cli/pull/721)

### 1.22.1

Expand Down
24 changes: 14 additions & 10 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,19 @@ 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 validationName != appName {
return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, appName)
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 {
validationName = appName
}

err = c.AppsDestroy(appName, validationName)
Expand Down
14 changes: 8 additions & 6 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (

var (
DestroyCommand = cli.Command{
Name: "destroy",
Category: "App Management",
Flags: []cli.Flag{appFlag},
Usage: "Destroy an app /!\\",
Description: "Destroy an app /!\\ It is not reversible\n Example:\n 'scalingo destroy my-app'\n 'scalingo -a my-app destroy'",
Name: "destroy",
Category: "App Management",
Flags: []cli.Flag{appFlag,
cli.BoolFlag{Name: "force", Usage: "Force destroy without asking for a confirmation /!\\", EnvVar: ""},
},
Usage: "Destroy an app /!\\",
Description: "Destroy an app /!\\ It is not reversible\n Example:\n 'scalingo destroy my-app'\n 'scalingo -a my-app destroy --force'\n ",
Action: func(c *cli.Context) {
var currentApp string

Expand All @@ -27,7 +29,7 @@ var (
currentApp = appdetect.CurrentApp(c)
}

err := apps.Destroy(currentApp)
err := apps.Destroy(currentApp, c.Bool("force"))
if err != nil {
errorQuit(err)
}
Expand Down