diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-05-04 11:20:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 11:20:12 -0400 |
commit | 89e60648404bfbcf9ea8d5cb84c01c1f5e72a890 (patch) | |
tree | b8d714804faa0a6b6f826908170e103470a11993 /cmd | |
parent | 3210a3f4257d19744abd4ae2302018b16edb2507 (diff) | |
parent | bea8301a8688073a03651ea23ff19bb760ec9e34 (diff) | |
download | podman-89e60648404bfbcf9ea8d5cb84c01c1f5e72a890.tar.gz podman-89e60648404bfbcf9ea8d5cb84c01c1f5e72a890.tar.bz2 podman-89e60648404bfbcf9ea8d5cb84c01c1f5e72a890.zip |
Merge pull request #14111 from openshift-cherrypick-robot/cherry-pick-14099-to-v4.1
[v4.1] Implement --format for machine inspect
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/machine/inspect.go | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/cmd/podman/machine/inspect.go b/cmd/podman/machine/inspect.go index 21e5074b7..a1f467bbb 100644 --- a/cmd/podman/machine/inspect.go +++ b/cmd/podman/machine/inspect.go @@ -7,10 +7,10 @@ import ( "encoding/json" "os" + "github.com/containers/common/pkg/report" "github.com/containers/podman/v4/cmd/podman/common" "github.com/containers/podman/v4/cmd/podman/registry" "github.com/containers/podman/v4/cmd/podman/utils" - "github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/pkg/machine" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -66,12 +66,29 @@ func inspect(cmd *cobra.Command, args []string) error { } vms = append(vms, *ii) } - if len(inspectFlag.format) > 0 { - // need jhonce to work his template magic - return define.ErrNotImplemented - } - if err := printJSON(vms); err != nil { - logrus.Error(err) + switch { + case cmd.Flag("format").Changed: + row := report.NormalizeFormat(inspectFlag.format) + row = report.EnforceRange(row) + + tmpl, err := report.NewTemplate("Machine inspect").Parse(row) + if err != nil { + return err + } + + w, err := report.NewWriterDefault(os.Stdout) + if err != nil { + return err + } + + if err := tmpl.Execute(w, vms); err != nil { + logrus.Error(err) + } + w.Flush() + default: + if err := printJSON(vms); err != nil { + logrus.Error(err) + } } return errs.PrintErrors() } |