Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

cli/destroy: Require confirmation to destroy all resources for app #1232

Merged
merged 6 commits into from
Mar 25, 2021
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
3 changes: 3 additions & 0 deletions .changelog/1232.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli/destroy: Require confirmation before destroying all resources
```
14 changes: 14 additions & 0 deletions internal/cli/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

type DestroyCommand struct {
*baseCommand

confirm bool
}

func (c *DestroyCommand) Run(args []string) int {
Expand All @@ -27,6 +29,11 @@ func (c *DestroyCommand) Run(args []string) int {
}

err := c.DoApp(c.Ctx, func(ctx context.Context, app *clientpkg.App) error {
if !c.confirm {
app.UI.Output("Destroying app %q requires confirmation with `-auto-approve`.", app.Ref().GetApplication(), terminal.WithWarningStyle())
return nil
}

if err := app.Destroy(ctx, &pb.Job_DestroyOp{
Target: &pb.Job_DestroyOp_Workspace{
Workspace: &empty.Empty{},
Expand All @@ -52,6 +59,13 @@ func (c *DestroyCommand) Run(args []string) int {

func (c *DestroyCommand) Flags() *flag.Sets {
return c.flagSet(flagSetOperation, func(set *flag.Sets) {
f := set.NewSet("Command Options")
f.BoolVar(&flag.BoolVar{
Name: "auto-approve",
Target: &c.confirm,
Default: false,
Usage: "Confirm destroying all resources.",
})
})
}

Expand Down