summaryrefslogtreecommitdiff
path: root/cmd/podman/volume_create.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/volume_create.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz
podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2
podman-25a3923b61a5ca014318e6d957f68abd03947297.zip
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the project is more well maintained. There are also some technical reasons as well which extend into our remote client work. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/volume_create.go')
-rw-r--r--cmd/podman/volume_create.go69
1 files changed, 32 insertions, 37 deletions
diff --git a/cmd/podman/volume_create.go b/cmd/podman/volume_create.go
index 0b5f8d1e3..e0ff4c341 100644
--- a/cmd/podman/volume_create.go
+++ b/cmd/podman/volume_create.go
@@ -3,75 +3,70 @@ package main
import (
"fmt"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
-var volumeCreateDescription = `
+var (
+ volumeCreateCommand cliconfig.VolumeCreateValues
+ volumeCreateDescription = `
podman volume create
Creates a new volume. If using the default driver, "local", the volume will
be created at.`
-var volumeCreateFlags = []cli.Flag{
- cli.StringFlag{
- Name: "driver",
- Usage: "Specify volume driver name (default local)",
- },
- cli.StringSliceFlag{
- Name: "label, l",
- Usage: "Set metadata for a volume (default [])",
- },
- cli.StringSliceFlag{
- Name: "opt, o",
- Usage: "Set driver specific options (default [])",
- },
-}
+ _volumeCreateCommand = &cobra.Command{
+ Use: "create",
+ Short: "Create a new volume",
+ Long: volumeCreateDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ volumeCreateCommand.InputArgs = args
+ volumeCreateCommand.GlobalFlags = MainGlobalOpts
+ return volumeCreateCmd(&volumeCreateCommand)
+ },
+ Example: "[VOLUME-NAME]",
+ }
+)
+
+func init() {
+ volumeCreateCommand.Command = _volumeCreateCommand
+ flags := volumeCreateCommand.Flags()
+ flags.StringVar(&volumeCreateCommand.Driver, "driver", "", "Specify volume driver name (default local)")
+ flags.StringSliceVarP(&volumeCreateCommand.Label, "label", "l", []string{}, "Set metadata for a volume (default [])")
+ flags.StringSliceVarP(&volumeCreateCommand.Opt, "opt", "o", []string{}, "Set driver specific options (default [])")
-var volumeCreateCommand = cli.Command{
- Name: "create",
- Usage: "Create a new volume",
- Description: volumeCreateDescription,
- Flags: volumeCreateFlags,
- Action: volumeCreateCmd,
- SkipArgReorder: true,
- ArgsUsage: "[VOLUME-NAME]",
- UseShortOptionHandling: true,
}
-func volumeCreateCmd(c *cli.Context) error {
+func volumeCreateCmd(c *cliconfig.VolumeCreateValues) error {
var (
options []libpod.VolumeCreateOption
err error
volName string
)
- if err = validateFlags(c, volumeCreateFlags); err != nil {
- return err
- }
-
- runtime, err := libpodruntime.GetRuntime(c)
+ 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()) > 1 {
+ if len(c.InputArgs) > 1 {
return errors.Errorf("too many arguments, create takes at most 1 argument")
}
- if len(c.Args()) > 0 {
- volName = c.Args()[0]
+ if len(c.InputArgs) > 0 {
+ volName = c.InputArgs[0]
options = append(options, libpod.WithVolumeName(volName))
}
- if c.IsSet("driver") {
+ if c.Flag("driver").Changed {
options = append(options, libpod.WithVolumeDriver(c.String("driver")))
}
- labels, err := getAllLabels([]string{}, c.StringSlice("label"))
+ labels, err := getAllLabels([]string{}, c.Label)
if err != nil {
return errors.Wrapf(err, "unable to process labels")
}
@@ -79,7 +74,7 @@ func volumeCreateCmd(c *cli.Context) error {
options = append(options, libpod.WithVolumeLabels(labels))
}
- opts, err := getAllLabels([]string{}, c.StringSlice("opt"))
+ opts, err := getAllLabels([]string{}, c.Opt)
if err != nil {
return errors.Wrapf(err, "unable to process options")
}