aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/machine/inspect.go20
-rw-r--r--pkg/machine/e2e/inspect_test.go8
2 files changed, 15 insertions, 13 deletions
diff --git a/cmd/podman/machine/inspect.go b/cmd/podman/machine/inspect.go
index d69c382f2..410bb3889 100644
--- a/cmd/podman/machine/inspect.go
+++ b/cmd/podman/machine/inspect.go
@@ -11,7 +11,6 @@ import (
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/cmd/podman/utils"
"github.com/containers/podman/v4/pkg/machine"
- "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -66,28 +65,23 @@ func inspect(cmd *cobra.Command, args []string) error {
}
vms = append(vms, *ii)
}
+
switch {
case cmd.Flag("format").Changed:
- row := report.NormalizeFormat(inspectFlag.format)
- row = report.EnforceRange(row)
+ rpt := report.New(os.Stdout, cmd.Name())
+ defer rpt.Flush()
- tmpl, err := report.NewTemplate("Machine inspect").Parse(row)
+ rpt, err := rpt.Parse(report.OriginUser, inspectFlag.format)
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)
+ if err := rpt.Execute(vms); err != nil {
+ errs = append(errs, err)
}
- w.Flush()
default:
if err := printJSON(vms); err != nil {
- logrus.Error(err)
+ errs = append(errs, err)
}
}
return errs.PrintErrors()
diff --git a/pkg/machine/e2e/inspect_test.go b/pkg/machine/e2e/inspect_test.go
index 0ab928205..fac9f7ebe 100644
--- a/pkg/machine/e2e/inspect_test.go
+++ b/pkg/machine/e2e/inspect_test.go
@@ -75,5 +75,13 @@ var _ = Describe("podman machine stop", func() {
Expect(err).To(BeNil())
Expect(inspectSession).To(Exit(0))
Expect(inspectSession.Bytes()).To(ContainSubstring(name))
+
+ // check invalid template returns error
+ inspect = new(inspectMachine)
+ inspect = inspect.withFormat("{{.Abcde}}")
+ inspectSession, err = mb.setName(name).setCmd(inspect).run()
+ Expect(err).To(BeNil())
+ Expect(inspectSession).To(Exit(125))
+ Expect(inspectSession.errorToString()).To(ContainSubstring("can't evaluate field Abcde in type machine.InspectInfo"))
})
})