Skip to content

Commit

Permalink
Merge pull request containers#9313 from jwhonce/issues/8773
Browse files Browse the repository at this point in the history
Add default template functions
  • Loading branch information
openshift-merge-robot authored Apr 5, 2021
2 parents 131458e + 3ed5607 commit 3fae801
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 2 additions & 10 deletions cmd/podman/inspect/inspect.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package inspect

import (
"bytes"
"context"
"encoding/json" // due to a bug in json-iterator it cannot be used here
"fmt"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3fae801

Please sign in to comment.