diff options
Diffstat (limited to 'cmd/podman/volume_inspect.go')
-rw-r--r-- | cmd/podman/volume_inspect.go | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/cmd/podman/volume_inspect.go b/cmd/podman/volume_inspect.go index 152f1d098..dc6afbc36 100644 --- a/cmd/podman/volume_inspect.go +++ b/cmd/podman/volume_inspect.go @@ -1,63 +1,58 @@ package main import ( - "github.com/containers/libpod/cmd/podman/libpodruntime" + "github.com/containers/libpod/cmd/podman/cliconfig" + "github.com/containers/libpod/pkg/adapter" "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) -var volumeInspectDescription = ` +var ( + volumeInspectCommand cliconfig.VolumeInspectValues + volumeInspectDescription = ` podman volume inspect Display detailed information on one or more volumes. Can change the format from JSON to a Go template. ` + _volumeInspectCommand = &cobra.Command{ + Use: "inspect", + Short: "Display detailed information on one or more volumes", + Long: volumeInspectDescription, + RunE: func(cmd *cobra.Command, args []string) error { + volumeInspectCommand.InputArgs = args + volumeInspectCommand.GlobalFlags = MainGlobalOpts + return volumeInspectCmd(&volumeInspectCommand) + }, + Example: `podman volume inspect myvol + podman volume inspect --all + podman volume inspect --format "{{.Driver}} {{.Scope}}" myvol`, + } +) -var volumeInspectFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "all, a", - Usage: "Inspect all volumes", - }, - cli.StringFlag{ - Name: "format, f", - Usage: "Format volume output using Go template", - Value: "json", - }, -} +func init() { + volumeInspectCommand.Command = _volumeInspectCommand + volumeInspectCommand.SetUsageTemplate(UsageTemplate()) + flags := volumeInspectCommand.Flags() + flags.BoolVarP(&volumeInspectCommand.All, "all", "a", false, "Inspect all volumes") + flags.StringVarP(&volumeInspectCommand.Format, "format", "f", "json", "Format volume output using Go template") -var volumeInspectCommand = cli.Command{ - Name: "inspect", - Usage: "Display detailed information on one or more volumes", - Description: volumeInspectDescription, - Flags: volumeInspectFlags, - Action: volumeInspectCmd, - SkipArgReorder: true, - ArgsUsage: "[VOLUME-NAME ...]", - UseShortOptionHandling: true, } -func volumeInspectCmd(c *cli.Context) error { - var err error - - if err = validateFlags(c, volumeInspectFlags); err != nil { - return err +func volumeInspectCmd(c *cliconfig.VolumeInspectValues) error { + if (c.All && len(c.InputArgs) > 0) || (!c.All && len(c.InputArgs) < 1) { + return errors.New("provide one or more volume names or use --all") } - runtime, err := libpodruntime.GetRuntime(c) + runtime, err := adapter.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "error creating libpod runtime") } defer runtime.Shutdown(false) - opts := volumeLsOptions{ - Format: c.String("format"), - } - - vols, lastError := getVolumesFromContext(c, runtime) - if lastError != nil { - logrus.Errorf("%q", lastError) + vols, err := runtime.InspectVolumes(getContext(), c) + if err != nil { + return err } - - return generateVolLsOutput(vols, opts, runtime) + return generateVolLsOutput(vols, volumeLsOptions{Format: c.Format}) } |