diff options
Diffstat (limited to 'cmd/podman/volumes/inspect.go')
-rw-r--r-- | cmd/podman/volumes/inspect.go | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/cmd/podman/volumes/inspect.go b/cmd/podman/volumes/inspect.go index ce24ac4e5..732a67333 100644 --- a/cmd/podman/volumes/inspect.go +++ b/cmd/podman/volumes/inspect.go @@ -3,10 +3,9 @@ package volumes import ( "fmt" "os" - "strings" "text/template" - "github.com/containers/buildah/pkg/formats" + "github.com/containers/common/pkg/report" "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/pkg/errors" @@ -19,7 +18,7 @@ var ( Use a Go template to change the format from JSON.` inspectCommand = &cobra.Command{ - Use: "inspect [flags] VOLUME [VOLUME...]", + Use: "inspect [options] VOLUME [VOLUME...]", Short: "Display detailed information on one or more volumes", Long: volumeInspectDescription, RunE: inspect, @@ -53,26 +52,21 @@ func inspect(cmd *cobra.Command, args []string) error { if err != nil { return err } - switch inspectFormat { - case "", formats.JSONString: + + switch { + case report.IsJSON(inspectFormat), inspectFormat == "": jsonOut, err := json.MarshalIndent(responses, "", " ") if err != nil { return errors.Wrapf(err, "error marshalling inspect JSON") } fmt.Println(string(jsonOut)) default: - if !strings.HasSuffix(inspectFormat, "\n") { - inspectFormat += "\n" - } - format := "{{range . }}" + inspectFormat + "{{end}}" - tmpl, err := template.New("volumeInspect").Parse(format) + row := "{{range . }}" + report.NormalizeFormat(inspectFormat) + "{{end}}" + tmpl, err := template.New("volumeInspect").Parse(row) if err != nil { return err } - if err := tmpl.Execute(os.Stdout, responses); err != nil { - return err - } + return tmpl.Execute(os.Stdout, responses) } return nil - } |