diff options
author | Jhon Honce <jhonce@redhat.com> | 2021-02-09 08:46:17 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2021-04-02 08:00:06 -0700 |
commit | 3ed56079f9483016d3aa3185f007a0063227fe09 (patch) | |
tree | 3f81363d7c1a9f0d88419db76936437ef4af1bf9 | |
parent | 1db9053add6501f2c234a6f63bb1e74b5eb89cb0 (diff) | |
download | podman-3ed56079f9483016d3aa3185f007a0063227fe09.tar.gz podman-3ed56079f9483016d3aa3185f007a0063227fe09.tar.bz2 podman-3ed56079f9483016d3aa3185f007a0063227fe09.zip |
Add default template functions
For commands that use the golang template library directly add the
compatible template functions
[NO TESTS NEEDED]
Fixes #8773
Signed-off-by: Jhon Honce <jhonce@redhat.com>
-rw-r--r-- | cmd/podman/containers/ps.go | 4 | ||||
-rw-r--r-- | cmd/podman/inspect/inspect.go | 12 |
2 files changed, 5 insertions, 11 deletions
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go index 6b125fede..70bfd3574 100644 --- a/cmd/podman/containers/ps.go +++ b/cmd/podman/containers/ps.go @@ -232,7 +232,9 @@ func ps(cmd *cobra.Command, _ []string) error { ns := strings.NewReplacer(".Namespaces.", ".") format = ns.Replace(format) - tmpl, err := template.New("listContainers").Parse(format) + tmpl, err := template.New("listContainers"). + Funcs(template.FuncMap(report.DefaultFuncs)). + Parse(format) if err != nil { return err } diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go index 09721a2a8..351684af1 100644 --- a/cmd/podman/inspect/inspect.go +++ b/cmd/podman/inspect/inspect.go @@ -1,7 +1,6 @@ package inspect import ( - "bytes" "context" "encoding/json" // due to a bug in json-iterator it cannot be used here "fmt" @@ -246,15 +245,8 @@ func printJSON(data []interface{}) error { } func printTmpl(typ, row string, data []interface{}) error { - t, err := template.New(typ + " inspect").Funcs(map[string]interface{}{ - "json": func(v interface{}) string { - b := &bytes.Buffer{} - e := registry.JSONLibrary().NewEncoder(b) - e.SetEscapeHTML(false) - _ = e.Encode(v) - return strings.TrimSpace(b.String()) - }, - }).Parse(row) + // We cannot use c/common/reports here, too many levels of interface{} + t, err := template.New(typ + " inspect").Funcs(template.FuncMap(report.DefaultFuncs)).Parse(row) if err != nil { return err } |