diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-19 18:19:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 18:19:43 +0100 |
commit | 093d9ef67341f474078bff1cba713caa0b10a692 (patch) | |
tree | bf5409bc6bc6ceeeb496ef7d7a140f2f24486835 /cmd/podmanV2/report/templates.go | |
parent | b43e249b1d9a8d63335e7c3ac88d6ac68b21e366 (diff) | |
parent | fbe743501e2a3ea28fe446754b9b12988b4e7a0e (diff) | |
download | podman-093d9ef67341f474078bff1cba713caa0b10a692.tar.gz podman-093d9ef67341f474078bff1cba713caa0b10a692.tar.bz2 podman-093d9ef67341f474078bff1cba713caa0b10a692.zip |
Merge pull request #5546 from jwhonce/wip/entities
V2 podman command
Diffstat (limited to 'cmd/podmanV2/report/templates.go')
-rw-r--r-- | cmd/podmanV2/report/templates.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/cmd/podmanV2/report/templates.go b/cmd/podmanV2/report/templates.go new file mode 100644 index 000000000..dc43d4f9b --- /dev/null +++ b/cmd/podmanV2/report/templates.go @@ -0,0 +1,61 @@ +package report + +import ( + "strings" + "text/template" + "time" + + "github.com/docker/go-units" +) + +var defaultFuncMap = template.FuncMap{ + "ellipsis": func(s string, length int) string { + if len(s) > length { + return s[:length-3] + "..." + } + return s + }, + // TODO: Remove on Go 1.14 port + "slice": func(s string, i, j int) string { + if i > j || len(s) < i { + return s + } + if len(s) < j { + return s[i:] + } + return s[i:j] + }, + "toRFC3339": func(t int64) string { + return time.Unix(t, 0).Format(time.RFC3339) + }, + "toHumanDuration": func(t int64) string { + return units.HumanDuration(time.Since(time.Unix(t, 0))) + " ago" + }, + "toHumanSize": func(sz int64) string { + return units.HumanSize(float64(sz)) + }, +} + +func ReportHeader(columns ...string) []byte { + hdr := make([]string, len(columns)) + for i, h := range columns { + hdr[i] = strings.ToUpper(h) + } + return []byte(strings.Join(hdr, "\t") + "\n") +} + +func AppendFuncMap(funcMap template.FuncMap) template.FuncMap { + merged := PodmanTemplateFuncs() + for k, v := range funcMap { + merged[k] = v + } + return merged +} + +func PodmanTemplateFuncs() template.FuncMap { + merged := make(template.FuncMap) + for k, v := range defaultFuncMap { + merged[k] = v + } + return merged +} |