-
Notifications
You must be signed in to change notification settings - Fork 161
/
configs.go
79 lines (65 loc) · 1.94 KB
/
configs.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 (
. "github.com/cloudfoundry/bosh-cli/cmd/opts"
boshdir "github.com/cloudfoundry/bosh-cli/director"
boshui "github.com/cloudfoundry/bosh-cli/ui"
boshtbl "github.com/cloudfoundry/bosh-cli/ui/table"
)
type ConfigsCmd struct {
ui boshui.UI
director boshdir.Director
}
func NewConfigsCmd(ui boshui.UI, director boshdir.Director) ConfigsCmd {
return ConfigsCmd{ui: ui, director: director}
}
func (c ConfigsCmd) Run(opts ConfigsOpts) error {
filter := boshdir.ConfigsFilter{
Type: opts.Type,
Name: opts.Name,
}
configs, err := c.director.ListConfigs(opts.Recent, filter)
if err != nil {
return err
}
var headers []boshtbl.Header
headers = append(headers, boshtbl.NewHeader("ID"))
headers = append(headers, boshtbl.NewHeader("Type"))
headers = append(headers, boshtbl.NewHeader("Name"))
headers = append(headers, boshtbl.NewHeader("Team"))
headers = append(headers, boshtbl.NewHeader("Created At"))
notes := []string{}
if atLeastOneConfigIsCurrent(configs) {
notes = append(notes, "(*) Currently active")
}
table := boshtbl.Table{
Content: "configs",
Header: headers,
Notes: notes,
}
if opts.Recent <= 1 {
table.Notes = append(table.Notes, "Only showing active configs. To see older versions use the --recent=10 option.")
}
for _, config := range configs {
var result []boshtbl.Value
idString := config.ID
if config.Current {
idString += "*"
}
result = append(result, boshtbl.NewValueString(idString))
result = append(result, boshtbl.NewValueString(config.Type))
result = append(result, boshtbl.NewValueString(config.Name))
result = append(result, boshtbl.NewValueString(config.Team))
result = append(result, boshtbl.NewValueString(config.CreatedAt))
table.Rows = append(table.Rows, result)
}
c.ui.PrintTable(table)
return nil
}
func atLeastOneConfigIsCurrent(configs []boshdir.Config) bool {
for _, config := range configs {
if config.Current {
return true
}
}
return false
}