/
collectors.go
48 lines (38 loc) · 1.2 KB
/
collectors.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
package print
import (
"strings"
"text/tabwriter"
"text/template"
"github.com/replicatedhq/replicated/pkg/types"
)
var collectorsTmplSrc = `NAME CREATED SPEC_ID ACTIVE_CHANNELS
{{ range . -}}
{{ .Name }} {{ time .CreatedAt }} {{ .SpecID }} {{ .ActiveChannels }}
{{ end }}`
var collectorsTmpl = template.Must(template.New("Collectors").Funcs(funcs).Parse(collectorsTmplSrc))
func Collectors(w *tabwriter.Writer, appCollectors []types.CollectorSpec) error {
rs := make([]map[string]interface{}, len(appCollectors))
for i, r := range appCollectors {
// join active channel names like "Stable,Unstable"
activeChans := make([]string, len(r.Channels))
for j, activeChan := range r.Channels {
activeChans[j] = activeChan.Name
}
activeChansField := strings.Join(activeChans, ",")
// don't print edited if it's the same as created
// edited := r.EditedAt.Format(time.RFC3339)
// if r.CreatedAt.Equal(r.EditedAt) {
// edited = ""
// }
rs[i] = map[string]interface{}{
"Name": r.Name,
"CreatedAt": r.CreatedAt,
"SpecID": r.ID,
"ActiveChannels": activeChansField,
}
}
if err := collectorsTmpl.Execute(w, rs); err != nil {
return err
}
return w.Flush()
}