aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/machine
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2022-05-03 10:51:58 -0700
committerJhon Honce <jhonce@redhat.com>2022-05-03 16:15:59 -0700
commit88015cf0d8c62e27452899c870555667d658427f (patch)
treed9708a4860381b4a29034811c3253c6096d94df8 /cmd/podman/machine
parent1e0c50df38ff955011f7ebb83a0268f3f1cd2841 (diff)
downloadpodman-88015cf0d8c62e27452899c870555667d658427f.tar.gz
podman-88015cf0d8c62e27452899c870555667d658427f.tar.bz2
podman-88015cf0d8c62e27452899c870555667d658427f.zip
Implement --format for machine inspect
* Fix issue of nil pointer derefence Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podman/machine')
-rw-r--r--cmd/podman/machine/inspect.go31
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()
}