summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-12-07 15:34:14 -0700
committerJhon Honce <jhonce@redhat.com>2020-12-07 15:39:43 -0700
commitce474788fd9bcecdb1cd6730fecd16e5d8840ae5 (patch)
tree1ddff0e68cb8a53244956212947cd8b37a301d87 /cmd
parente2f91207fc3e515c0a9f828433aaf80727f4b7c5 (diff)
downloadpodman-ce474788fd9bcecdb1cd6730fecd16e5d8840ae5.tar.gz
podman-ce474788fd9bcecdb1cd6730fecd16e5d8840ae5.tar.bz2
podman-ce474788fd9bcecdb1cd6730fecd16e5d8840ae5.zip
Restore json format for fields as well as whole structs
* Add template func to inspect template processing * Added test using repro from #8444 Fixes #8444 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/inspect/inspect.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go
index 13f36ebbd..cc48b7ae4 100644
--- a/cmd/podman/inspect/inspect.go
+++ b/cmd/podman/inspect/inspect.go
@@ -1,6 +1,7 @@
package inspect
import (
+ "bytes"
"context"
"encoding/json" // due to a bug in json-iterator it cannot be used here
"fmt"
@@ -245,7 +246,15 @@ func printJSON(data []interface{}) error {
}
func printTmpl(typ, row string, data []interface{}) error {
- t, err := template.New(typ + " inspect").Parse(row)
+ 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)
if err != nil {
return err
}