forked from ehazlett/shipyard
/
destroy.go
43 lines (39 loc) · 922 Bytes
/
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
package main
import (
"fmt"
"strings"
"github.com/codegangsta/cli"
"github.com/shipyard/shipyard/client"
)
var destroyCommand = cli.Command{
Name: "destroy",
Usage: "destroy a container",
Description: "destroy <id> [<id>]",
Action: destroyAction,
}
func destroyAction(c *cli.Context) {
cfg, err := loadConfig()
if err != nil {
logger.Fatal(err)
}
m := client.NewManager(cfg)
containers, err := m.Containers()
if err != nil {
logger.Fatalf("error getting container info: %s", err)
}
ids := c.Args()
if len(ids) == 0 {
logger.Fatalf("you must specify at least one id")
}
for _, cnt := range containers {
// this can probably be more efficient
for _, i := range ids {
if strings.HasPrefix(cnt.ID, i) {
if err := m.Destroy(cnt); err != nil {
logger.Fatalf("error destroying container: %s\n", err)
}
fmt.Printf("destroyed %s\n", cnt.ID[:12])
}
}
}
}