-
Notifications
You must be signed in to change notification settings - Fork 239
/
destroy.go
72 lines (56 loc) · 1.62 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package apps
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/internal/flag/completion"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/flag"
"github.com/superfly/flyctl/internal/prompt"
)
func newDestroy() *cobra.Command {
const (
long = `The APPS DESTROY command will remove an application
from the Fly platform.
`
short = "Permanently destroys an app"
usage = "destroy <APPNAME>"
)
destroy := command.New(usage, short, long, RunDestroy,
command.RequireSession)
destroy.Args = cobra.ExactArgs(1)
flag.Add(destroy,
flag.Yes(),
)
destroy.ValidArgsFunction = completion.Adapt(completion.CompleteApps)
destroy.Aliases = []string{"delete", "remove", "rm"}
return destroy
}
// TODO: make internal once the destroy package is removed
func RunDestroy(ctx context.Context) error {
io := iostreams.FromContext(ctx)
colorize := io.ColorScheme()
appName := flag.FirstArg(ctx)
client := client.FromContext(ctx).API()
if !flag.GetYes(ctx) {
const msg = "Destroying an app is not reversible."
fmt.Fprintln(io.ErrOut, colorize.Red(msg))
switch confirmed, err := prompt.Confirmf(ctx, "Destroy app %s?", appName); {
case err == nil:
if !confirmed {
return nil
}
case prompt.IsNonInteractive(err):
return prompt.NonInteractiveError("yes flag must be specified when not running interactively")
default:
return err
}
}
if err := client.DeleteApp(ctx, appName); err != nil {
return err
}
fmt.Fprintf(io.Out, "Destroyed app %s\n", appName)
return nil
}