-
Notifications
You must be signed in to change notification settings - Fork 162
/
deployments_table.go
68 lines (55 loc) · 1.41 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
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: []string{"Name", "Release(s)", "Stemcell(s)", "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
}
config, 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.NewValueString(config),
})
}
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
}