This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
views.go
66 lines (60 loc) · 1.87 KB
/
views.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
package main
import (
"github.com/docker/docker/api/types"
"io"
"text/tabwriter"
"text/template"
)
func render(name string, out io.Writer, data interface{}) error {
t := template.Must(template.New(name).Funcs(funcMap).Parse(views[name]))
return t.Execute(out, data)
}
func renderTabbed(name string, out io.Writer, data interface{}) error {
t := template.Must(template.New(name).Funcs(funcMap).Parse(views[name]))
w := tabwriter.NewWriter(out, 16, 16, 16, ' ', 0)
err := t.Execute(w, data)
if err == nil {
w.Flush()
}
return err
}
func renderRemoved(out io.Writer, gone []types.ImageDelete, ie error) error {
t := template.Must(template.New(`removedImage`).Funcs(funcMap).Parse(views[`removedImage`]))
w := tabwriter.NewWriter(out, 16, 16, 16, ' ', 0)
err := t.Execute(w, struct {
Gone []types.ImageDelete
}{gone})
if err == nil {
w.Flush()
} else {
return err
}
return ie
}
var funcMap = template.FuncMap{
"tail8": func(c string) string { return c[len(c)-8:] },
"tail12": func(c string) string { return c[len(c)-12:] },
"head8": func(c string) string { return c[:8] },
"head12": func(c string) string { return c[:12] },
"stripSha": func(c string) string { return c[7:] },
"orNone": func(c string) string {
if len(c) == 0 {
return `-`
}
return c
},
}
var views = map[string]string{
`imageList`: `ID REPOSITORY TAG ORIGINAL CREATED{{ range .Products }}
{{.ImageID | stripSha | head12}} {{.Repository}} {{.Tag}} {{.Original}} {{.Created}}{{ end }}
`,
`detectiveList`: `REPOSITORY TAG CATEGORY DESCRIPTION{{ range .Detectives }}
{{.Repository}} {{.Tag}} {{.Category}} {{.Description}}{{ end }}
`,
`provisionerList`: `REPOSITORY TAG CATEGORY DESCRIPTION{{ range .Provisioners }}
{{.Repository}} {{.Tag}} {{.Category}} {{.Description}}{{ end }}
`,
`removedImage`: `UNTAGGED DELETED{{ range .Gone }}
{{.Untagged | orNone}} {{.Deleted | orNone }}{{ end }}
`,
}