aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/rmi.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/rmi.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/rmi.go')
-rw-r--r--cmd/podman/rmi.go63
1 files changed, 26 insertions, 37 deletions
diff --git a/cmd/podman/rmi.go b/cmd/podman/rmi.go
index 39757272e..70f58e844 100644
--- a/cmd/podman/rmi.go
+++ b/cmd/podman/rmi.go
@@ -4,47 +4,39 @@ import (
"fmt"
"os"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod/adapter"
"github.com/containers/storage"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
+ rmiCommand cliconfig.RmiValues
rmiDescription = "Removes one or more locally stored images."
- rmiFlags = []cli.Flag{
- cli.BoolFlag{
- Name: "all, a",
- Usage: "Remove all images",
+ _rmiCommand = &cobra.Command{
+ Use: "rmi",
+ Short: "Removes one or more images from local storage",
+ Long: rmiDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ rmiCommand.InputArgs = args
+ rmiCommand.GlobalFlags = MainGlobalOpts
+ return rmiCmd(&rmiCommand)
},
- cli.BoolFlag{
- Name: "force, f",
- Usage: "Force removal of the image",
- },
- }
- rmiCommand = cli.Command{
- Name: "rmi",
- Usage: "Remove one or more images from local storage",
- Description: rmiDescription,
- Action: rmiCmd,
- ArgsUsage: "IMAGE-NAME-OR-ID [...]",
- Flags: sortFlags(rmiFlags),
- UseShortOptionHandling: true,
- OnUsageError: usageErrorHandler,
- }
- rmImageCommand = cli.Command{
- Name: "rm",
- Usage: "Removes one or more images from local storage",
- Description: rmiDescription,
- Action: rmiCmd,
- ArgsUsage: "IMAGE-NAME-OR-ID [...]",
- Flags: rmiFlags,
- UseShortOptionHandling: true,
- OnUsageError: usageErrorHandler,
+ Example: "IMAGE-NAME-OR-ID [...]",
}
)
-func rmiCmd(c *cli.Context) error {
+func init() {
+ rmiCommand.Command = _rmiCommand
+ flags := rmiCommand.Flags()
+ flags.BoolVarP(&rmiCommand.All, "all", "a", false, "Remove all images")
+ flags.BoolVarP(&rmiCommand.Force, "force", "f", false, "Force Removal of the image")
+
+ rootCmd.AddCommand(rmiCommand.Command)
+}
+
+func rmiCmd(c *cliconfig.RmiValues) error {
var (
lastError error
deleted bool
@@ -53,17 +45,14 @@ func rmiCmd(c *cli.Context) error {
)
ctx := getContext()
- if err := validateFlags(c, rmiFlags); err != nil {
- return err
- }
- removeAll := c.Bool("all")
- runtime, err := adapter.GetRuntime(c)
+ removeAll := c.All
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- args := c.Args()
+ args := c.InputArgs
if len(args) == 0 && !removeAll {
return errors.Errorf("image name or ID must be specified")
}
@@ -75,7 +64,7 @@ func rmiCmd(c *cli.Context) error {
removeImage := func(img *adapter.ContainerImage) {
deleted = true
- msg, deleteErr = runtime.RemoveImage(ctx, img, c.Bool("force"))
+ msg, deleteErr = runtime.RemoveImage(ctx, img, c.Force)
if deleteErr != nil {
if errors.Cause(deleteErr) == storage.ErrImageUsedByContainer {
fmt.Printf("A container associated with containers/storage, i.e. via Buildah, CRI-O, etc., may be associated with this image: %-12.12s\n", img.ID())