forked from mantika/whaleprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestroy.go
57 lines (47 loc) · 1.16 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
package main
import (
"fmt"
"log"
"strings"
"golang.org/x/net/context"
"github.com/docker/engine-api/client"
"github.com/fatih/color"
"github.com/urfave/cli"
)
func destroy(c *cli.Context) error {
stacks, err := getStacks(c)
if err != nil {
return err
}
var services []string
for _, stack := range stacks {
for name, _ := range stack.Bundle.Services {
services = append(services, fmt.Sprintf("%s_%s", stack.Name, name))
}
}
force := c.Bool("force")
swarm, swarmErr := client.NewEnvClient()
if swarmErr != nil {
return cli.NewExitError(swarmErr.Error(), 3)
}
if !force {
fmt.Printf("Are you sure you want to remove the following services? (%s) yes/no: ", strings.Join(services, ", "))
var input string
fmt.Scanln(&input)
switch {
case input == "no":
log.Fatal("Aborting")
case input == "yes":
default:
log.Fatalf("Incorrect option \"%s\", aborting", input)
}
}
for _, service := range services {
color.Cyan("Removing service %s\n", service)
servicesErr := swarm.ServiceRemove(context.Background(), service)
if servicesErr != nil {
log.Println("Error removing service %s:, %s", service, err)
}
}
return nil
}