forked from remind101/empire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestroy.go
55 lines (46 loc) · 1.32 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
package main
import (
"fmt"
"log"
"os/exec"
)
var cmdDestroy = &Command{
Run: confirmDestroy(maybeMessage(runDestroy)),
Usage: "destroy <name>",
OptionalMessage: true,
Category: "app",
Short: "destroy an app",
NumArgs: 1,
Long: `
Destroy destroys a heroku app. There is no going back, so be
sure you mean it. The command will prompt for confirmation, or
accept confirmation via stdin.
Example:
$ emp destroy myapp
warning: This will destroy myapp and its add-ons. Please type "myapp" to continue:
Destroyed myapp.
$ echo myapp | emp destroy myapp
Destroyed myapp.
`,
}
func confirmDestroy(action func(cmd *Command, args []string)) func(cmd *Command, args []string) {
return func(cmd *Command, args []string) {
cmd.AssertNumArgsCorrect(args)
appname := args[0]
warning := fmt.Sprintf("This will destroy %s and its add-ons. Please type %q to continue:", appname, appname)
mustConfirm(warning, appname)
action(cmd, args)
}
}
func runDestroy(cmd *Command, args []string) {
message := getMessage()
appname := args[0]
must(client.AppDelete(appname, message))
log.Printf("Destroyed %s.", appname)
remotes, _ := gitRemotes()
for remote, remoteApp := range remotes {
if appname == remoteApp {
exec.Command("git", "remote", "rm", remote).Run()
}
}
}