forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployments_table.go
80 lines (66 loc) · 1.64 KB
/
deployments_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
package cmd
import (
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type DeploymentsTable struct {
Deployments []boshdir.Deployment
UI boshui.UI
}
func (t DeploymentsTable) Print() error {
table := boshtbl.Table{
Content: "deployments",
Header: []boshtbl.Header{
boshtbl.NewHeader("Name"),
boshtbl.NewHeader("Release(s)"),
boshtbl.NewHeader("Stemcell(s)"),
boshtbl.NewHeader("Team(s)"),
boshtbl.NewHeader("Cloud Config"),
},
SortBy: []boshtbl.ColumnSort{
{Column: 0, Asc: true},
},
}
for _, d := range t.Deployments {
releases, err := d.Releases()
if err != nil {
return err
}
stemcells, err := d.Stemcells()
if err != nil {
return err
}
teams, err := d.Teams()
if err != nil {
return err
}
cloudConfig, err := d.CloudConfig()
if err != nil {
return err
}
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString(d.Name()),
boshtbl.NewValueStrings(t.takeReleases(releases)),
boshtbl.NewValueStrings(t.takeStemcells(stemcells)),
boshtbl.NewValueStrings(teams),
boshtbl.NewValueString(cloudConfig),
})
}
t.UI.PrintTable(table)
return nil
}
func (t DeploymentsTable) takeReleases(rels []boshdir.Release) []string {
var names []string
for _, r := range rels {
names = append(names, r.Name()+"/"+r.Version().String())
}
return names
}
func (t DeploymentsTable) takeStemcells(stemcells []boshdir.Stemcell) []string {
var names []string
for _, s := range stemcells {
names = append(names, s.Name()+"/"+s.Version().String())
}
return names
}