mirror of
https://github.com/containers/podman.git
synced 2025-06-24 11:28:24 +08:00
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>
This commit is contained in:
@ -232,7 +232,9 @@ func ps(cmd *cobra.Command, _ []string) error {
|
|||||||
ns := strings.NewReplacer(".Namespaces.", ".")
|
ns := strings.NewReplacer(".Namespaces.", ".")
|
||||||
format = ns.Replace(format)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package inspect
|
package inspect
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json" // due to a bug in json-iterator it cannot be used here
|
"encoding/json" // due to a bug in json-iterator it cannot be used here
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -246,15 +245,8 @@ func printJSON(data []interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printTmpl(typ, row string, data []interface{}) error {
|
func printTmpl(typ, row string, data []interface{}) error {
|
||||||
t, err := template.New(typ + " inspect").Funcs(map[string]interface{}{
|
// We cannot use c/common/reports here, too many levels of interface{}
|
||||||
"json": func(v interface{}) string {
|
t, err := template.New(typ + " inspect").Funcs(template.FuncMap(report.DefaultFuncs)).Parse(row)
|
||||||
b := &bytes.Buffer{}
|
|
||||||
e := registry.JSONLibrary().NewEncoder(b)
|
|
||||||
e.SetEscapeHTML(false)
|
|
||||||
_ = e.Encode(v)
|
|
||||||
return strings.TrimSpace(b.String())
|
|
||||||
},
|
|
||||||
}).Parse(row)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user