forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info_table.go
81 lines (67 loc) · 1.75 KB
/
info_table.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cmd
import (
"fmt"
"sort"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type InfoTable struct {
Info boshdir.Info
UI boshui.UI
}
func (t InfoTable) Print() {
table := boshtbl.Table{
Rows: [][]boshtbl.Value{
{
boshtbl.NewValueString("Name"),
boshtbl.NewValueString(t.Info.Name),
},
{
boshtbl.NewValueString("UUID"),
boshtbl.NewValueString(t.Info.UUID),
},
{
boshtbl.NewValueString("Version"),
boshtbl.NewValueString(t.Info.Version),
},
},
}
if len(t.Info.CPI) > 0 {
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString("CPI"),
boshtbl.NewValueString(t.Info.CPI),
})
}
if len(t.Info.Features) > 0 {
desc := []string{}
enabledText := map[bool]string{
true: "enabled",
false: "disabled",
}
for name, enabled := range t.Info.Features {
desc = append(desc, fmt.Sprintf("%s: %s", name, enabledText[enabled]))
}
sort.Sort(InfoFeatureSorting(desc))
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString("Features"),
boshtbl.NewValueStrings(desc),
})
}
if len(t.Info.User) > 0 {
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString("User"),
boshtbl.NewValueString(t.Info.User),
})
} else {
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString("User"),
boshtbl.NewValueString("(not logged in)"),
})
}
t.UI.PrintTable(table)
}
type InfoFeatureSorting []string
func (s InfoFeatureSorting) Len() int { return len(s) }
func (s InfoFeatureSorting) Less(i, j int) bool { return s[i] < s[j] }
func (s InfoFeatureSorting) Swap(i, j int) { s[i], s[j] = s[j], s[i] }