-
Notifications
You must be signed in to change notification settings - Fork 235
/
destroy.go
58 lines (40 loc) · 1.21 KB
/
destroy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cmd
import (
"fmt"
"github.com/superfly/flyctl/cmdctx"
"github.com/superfly/flyctl/internal/client"
"github.com/AlecAivazis/survey/v2"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/docstrings"
)
//TODO: Move all output to status styled begin/done updates
func newDestroyCommand(client *client.Client) *Command {
destroyStrings := docstrings.Get("destroy")
destroy := BuildCommand(nil, runDestroy, destroyStrings.Usage, destroyStrings.Short, destroyStrings.Long, client, requireSession)
destroy.Args = cobra.ExactArgs(1)
destroy.AddBoolFlag(BoolFlagOpts{Name: "yes", Shorthand: "y", Description: "Accept all confirmations"})
return destroy
}
func runDestroy(ctx *cmdctx.CmdContext) error {
appName := ctx.Args[0]
if !ctx.Config.GetBool("yes") {
fmt.Println(aurora.Red("Destroying an app is not reversible."))
confirm := false
prompt := &survey.Confirm{
Message: fmt.Sprintf("Destroy app %s?", appName),
}
err := survey.AskOne(prompt, &confirm)
if err != nil {
return err
}
if !confirm {
return nil
}
}
if err := ctx.Client.API().DeleteApp(appName); err != nil {
return err
}
fmt.Println("Destroyed app", appName)
return nil
}