-
Notifications
You must be signed in to change notification settings - Fork 162
/
deployment_table.go
76 lines (62 loc) · 1.67 KB
/
deployment_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
package cmd
import (
"fmt"
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"
)
type DeploymentTablePrinter struct {
Name string
Releases []boshdir.Release
Stemcells []boshdir.Stemcell
Teams []string
Configs boshdir.DeploymentConfigs
UI boshui.UI
}
func (t DeploymentTablePrinter) Print() error {
headers := []boshtbl.Header{
boshtbl.NewHeader("Name"),
boshtbl.NewHeader("Release(s)"),
boshtbl.NewHeader("Stemcell(s)"),
boshtbl.NewHeader("Config(s)"),
boshtbl.NewHeader("Team(s)"),
}
rows := []boshtbl.Value{
boshtbl.NewValueString(t.Name),
boshtbl.NewValueStrings(formatReleases(t.Releases)),
boshtbl.NewValueStrings(formatStemcells(t.Stemcells)),
boshtbl.NewValueStrings(formatConfigs(t.Configs)),
boshtbl.NewValueStrings(t.Teams),
}
table := boshtbl.Table{
Content: "deployments",
Header: headers,
SortBy: []boshtbl.ColumnSort{
{Column: 0, Asc: true},
},
}
table.Rows = append(table.Rows, rows)
t.UI.PrintTable(table)
return nil
}
func formatReleases(rels []boshdir.Release) []string {
var names []string
for _, r := range rels {
names = append(names, r.Name()+"/"+r.Version().String())
}
return names
}
func formatStemcells(stemcells []boshdir.Stemcell) []string {
var names []string
for _, s := range stemcells {
names = append(names, s.Name()+"/"+s.Version().String())
}
return names
}
func formatConfigs(configs boshdir.DeploymentConfigs) []string {
var names []string
for _, c := range configs.GetConfigs() {
names = append(names, fmt.Sprintf("%d %s/%s", c.Id, c.Type, c.Name))
}
return names
}