diff options
author | baude <bbaude@redhat.com> | 2019-01-31 13:20:04 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-02-08 10:26:43 -0600 |
commit | 25a3923b61a5ca014318e6d957f68abd03947297 (patch) | |
tree | 2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/volume_prune.go | |
parent | 962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff) | |
download | podman-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_prune.go')
-rw-r--r-- | cmd/podman/volume_prune.go | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/cmd/podman/volume_prune.go b/cmd/podman/volume_prune.go index 41d95f9c7..29dc6ead4 100644 --- a/cmd/podman/volume_prune.go +++ b/cmd/podman/volume_prune.go @@ -7,35 +7,39 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/adapter" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) -var volumePruneDescription = ` +var ( + volumePruneCommand cliconfig.VolumePruneValues + volumePruneDescription = ` podman volume prune Remove all unused volumes. Will prompt for confirmation if not using force. ` + _volumePruneCommand = &cobra.Command{ + Use: "prune", + Short: "Remove all unused volumes", + Long: volumePruneDescription, + RunE: func(cmd *cobra.Command, args []string) error { + volumePruneCommand.InputArgs = args + volumePruneCommand.GlobalFlags = MainGlobalOpts + return volumePruneCmd(&volumePruneCommand) + }, + } +) -var volumePruneFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "force, f", - Usage: "Do not prompt for confirmation", - }, -} +func init() { + volumePruneCommand.Command = _volumePruneCommand + flags := volumePruneCommand.Flags() -var volumePruneCommand = cli.Command{ - Name: "prune", - Usage: "Remove all unused volumes", - Description: volumePruneDescription, - Flags: volumePruneFlags, - Action: volumePruneCmd, - SkipArgReorder: true, - UseShortOptionHandling: true, + flags.BoolVarP(&volumePruneCommand.Force, "force", "f", false, "Do not prompt for confirmation") } func volumePrune(runtime *adapter.LocalRuntime, ctx context.Context) error { @@ -60,20 +64,15 @@ func volumePrune(runtime *adapter.LocalRuntime, ctx context.Context) error { return lastError } -func volumePruneCmd(c *cli.Context) error { - - if err := validateFlags(c, volumePruneFlags); err != nil { - return err - } - - runtime, err := adapter.GetRuntime(c) +func volumePruneCmd(c *cliconfig.VolumePruneValues) error { + runtime, err := adapter.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "error creating libpod runtime") } defer runtime.Shutdown(false) // Prompt for confirmation if --force is not set - if !c.Bool("force") { + if !c.Force { reader := bufio.NewReader(os.Stdin) fmt.Println("WARNING! This will remove all volumes not used by at least one container.") fmt.Print("Are you sure you want to continue? [y/N] ") |