summaryrefslogtreecommitdiff
path: root/cmd/podman/volume_ls.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-08 20:12:38 +0100
committerGitHub <noreply@github.com>2019-02-08 20:12:38 +0100
commitafd4d5f4a4b05f421e6f336b4d74a0d808be57ed (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/volume_ls.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
parent25a3923b61a5ca014318e6d957f68abd03947297 (diff)
downloadpodman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.tar.gz
podman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.tar.bz2
podman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.zip
Merge pull request #2274 from baude/cobraprep
Migrate to cobra CLI
Diffstat (limited to 'cmd/podman/volume_ls.go')
-rw-r--r--cmd/podman/volume_ls.go74
1 files changed, 34 insertions, 40 deletions
diff --git a/cmd/podman/volume_ls.go b/cmd/podman/volume_ls.go
index 0f94549ee..78fdfed64 100644
--- a/cmd/podman/volume_ls.go
+++ b/cmd/podman/volume_ls.go
@@ -4,11 +4,12 @@ import (
"reflect"
"strings"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
// volumeOptions is the "ls" command options
@@ -37,64 +38,57 @@ type volumeLsJSONParams struct {
Scope string `json:"scope"`
}
-var volumeLsDescription = `
+var (
+ volumeLsCommand cliconfig.VolumeLsValues
+
+ volumeLsDescription = `
podman volume ls
List all available volumes. The output of the volumes can be filtered
and the output format can be changed to JSON or a user specified Go template.
`
+ _volumeLsCommand = &cobra.Command{
+ Use: "ls",
+ Aliases: []string{"list"},
+ Short: "List volumes",
+ Long: volumeLsDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ volumeLsCommand.InputArgs = args
+ volumeLsCommand.GlobalFlags = MainGlobalOpts
+ return volumeLsCmd(&volumeLsCommand)
+ },
+ }
+)
-var volumeLsFlags = []cli.Flag{
- cli.StringFlag{
- Name: "filter, f",
- Usage: "Filter volume output",
- },
- cli.StringFlag{
- Name: "format",
- Usage: "Format volume output using Go template",
- Value: "table {{.Driver}}\t{{.Name}}",
- },
- cli.BoolFlag{
- Name: "quiet, q",
- Usage: "Print volume output in quiet mode",
- },
-}
+func init() {
+ volumeLsCommand.Command = _volumeLsCommand
+ flags := volumeLsCommand.Flags()
-var volumeLsCommand = cli.Command{
- Name: "ls",
- Aliases: []string{"list"},
- Usage: "List volumes",
- Description: volumeLsDescription,
- Flags: volumeLsFlags,
- Action: volumeLsCmd,
- SkipArgReorder: true,
- UseShortOptionHandling: true,
+ flags.StringVarP(&volumeLsCommand.Filter, "filter", "f", "", "Filter volume output")
+ flags.StringVar(&volumeLsCommand.Format, "format", "table {{.Driver}}\t{{.Name}}", "Format volume output using Go template")
+ flags.BoolVarP(&volumeLsCommand.Quiet, "quiet", "q", false, "Print volume output in quiet mode")
}
-func volumeLsCmd(c *cli.Context) error {
- if err := validateFlags(c, volumeLsFlags); err != nil {
- return err
- }
-
- runtime, err := libpodruntime.GetRuntime(c)
+func volumeLsCmd(c *cliconfig.VolumeLsValues) error {
+ runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- if len(c.Args()) > 0 {
+ if len(c.InputArgs) > 0 {
return errors.Errorf("too many arguments, ls takes no arguments")
}
opts := volumeLsOptions{
- Quiet: c.Bool("quiet"),
+ Quiet: c.Quiet,
}
opts.Format = genVolLsFormat(c)
// Get the filter functions based on any filters set
var filterFuncs []libpod.VolumeFilter
- if c.String("filter") != "" {
- filters := strings.Split(c.String("filter"), ",")
+ if c.Filter != "" {
+ filters := strings.Split(c.Filter, ",")
for _, f := range filters {
filterSplit := strings.Split(f, "=")
if len(filterSplit) < 2 {
@@ -129,14 +123,14 @@ func volumeLsCmd(c *cli.Context) error {
}
// generate the template based on conditions given
-func genVolLsFormat(c *cli.Context) string {
+func genVolLsFormat(c *cliconfig.VolumeLsValues) string {
var format string
- if c.String("format") != "" {
+ if c.Format != "" {
// "\t" from the command line is not being recognized as a tab
// replacing the string "\t" to a tab character if the user passes in "\t"
- format = strings.Replace(c.String("format"), `\t`, "\t", -1)
+ format = strings.Replace(c.Format, `\t`, "\t", -1)
}
- if c.Bool("quiet") {
+ if c.Quiet {
format = "{{.Name}}"
}
return format