forked from ehazlett/shipyard
/
stop.go
43 lines (39 loc) · 897 Bytes
/
stop.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 stopCommand = cli.Command{
Name: "stop",
Usage: "stop a container",
Description: "stop <id> [<id>]",
Action: stopAction,
}
func stopAction(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.Stop(cnt); err != nil {
logger.Fatalf("error stopping container: %s\n", err)
}
fmt.Printf("stopped %s\n", cnt.ID[:12])
}
}
}
}