/
status.go
56 lines (46 loc) · 1.1 KB
/
status.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
package status
import (
"os"
"strings"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/frozzare/alfred/cli/root"
"github.com/frozzare/alfred/config"
"github.com/frozzare/alfred/internal/docker"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
)
func init() {
cmd := root.Command("status", "Show application statuses")
cmd.Action(func(_ *kingpin.ParseContext) error {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Host",
"Status",
"Image",
"Start Time",
})
table.SetAlignment(tablewriter.ALIGN_LEFT)
d, err := docker.NewDocker(&docker.Config{
Host: config.Global().Docker.Host,
})
if err != nil {
return errors.Wrap(err, "Docker")
}
cos, err := d.FindContainers(map[string][]string{
"label": []string{"alfred=true"},
})
if err != nil {
return errors.Wrap(err, "Docker")
}
for _, co := range cos {
table.Append([]string{
strings.Replace(co.Name, "/", "", -1),
strings.Title(co.State.StateString()),
co.Image,
co.State.StartedAt.Format("2006-01-02 15:04:05"),
})
}
table.Render()
return nil
})
}