-
Notifications
You must be signed in to change notification settings - Fork 162
/
deployments_table.go
79 lines (68 loc) · 1.92 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
package cmd
import (
boshdir "github.com/cloudfoundry/bosh-cli/v7/director"
boshui "github.com/cloudfoundry/bosh-cli/v7/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/v7/ui/table"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
semver "github.com/cppforlife/go-semi-semantic/version"
)
type DeploymentsTable struct {
Deployments []boshdir.DeploymentResp
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)"),
},
SortBy: []boshtbl.ColumnSort{
{Column: 0, Asc: true},
},
}
for _, d := range t.Deployments {
releases, err := takeReleases(d.Releases)
if err != nil {
return err
}
stemcells, err := takeStemcells(d.Stemcells)
if err != nil {
return err
}
table.Rows = append(table.Rows, []boshtbl.Value{
boshtbl.NewValueString(d.Name),
boshtbl.NewValueStrings(releases),
boshtbl.NewValueStrings(stemcells),
boshtbl.NewValueStrings(d.Teams),
})
}
t.UI.PrintTable(table)
return nil
}
func takeReleases(rels []boshdir.DeploymentReleaseResp) ([]string, error) {
var names []string
for _, r := range rels {
parsedVersion, err := semver.NewVersionFromString(r.Version)
if err != nil {
return nil, bosherr.WrapErrorf(
err, "Parsing version for release '%s/%s'", r.Name, r.Version)
}
names = append(names, r.Name+"/"+parsedVersion.String())
}
return names, nil
}
func takeStemcells(stemcells []boshdir.DeploymentStemcellResp) ([]string, error) {
var names []string
for _, s := range stemcells {
parsedVersion, err := semver.NewVersionFromString(s.Version)
if err != nil {
return nil, bosherr.WrapErrorf(
err, "Parsing version for stemcell '%s/%s'", s.Name, s.Version)
}
names = append(names, s.Name+"/"+parsedVersion.String())
}
return names, nil
}