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/system_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/system_prune.go')
-rw-r--r-- | cmd/podman/system_prune.go | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/cmd/podman/system_prune.go b/cmd/podman/system_prune.go index 64d291560..c918fbe3b 100644 --- a/cmd/podman/system_prune.go +++ b/cmd/podman/system_prune.go @@ -6,50 +6,50 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod/adapter" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) var ( + pruneSystemCommand cliconfig.SystemPruneValues pruneSystemDescription = ` podman system prune Remove unused data ` - pruneSystemFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "all, a", - Usage: "Remove all unused data", - }, - cli.BoolFlag{ - Name: "force, f", - Usage: "Do not prompt for confirmation", - }, - cli.BoolFlag{ - Name: "volumes", - Usage: "Prune volumes", + _pruneSystemCommand = &cobra.Command{ + Use: "prune", + Short: "Remove unused data", + Long: pruneSystemDescription, + RunE: func(cmd *cobra.Command, args []string) error { + pruneSystemCommand.InputArgs = args + pruneSystemCommand.GlobalFlags = MainGlobalOpts + return pruneSystemCmd(&pruneSystemCommand) }, } - pruneSystemCommand = cli.Command{ - Name: "prune", - Usage: "Remove unused data", - Description: pruneSystemDescription, - Action: pruneSystemCmd, - OnUsageError: usageErrorHandler, - Flags: pruneSystemFlags, - } ) -func pruneSystemCmd(c *cli.Context) error { +func init() { + + pruneSystemCommand.Command = _pruneSystemCommand + flags := pruneSystemCommand.Flags() + flags.BoolVarP(&pruneSystemCommand.All, "all", "a", false, "Remove all unused data") + flags.BoolVarP(&pruneSystemCommand.Force, "force", "f", false, "Do not prompt for confirmation") + flags.BoolVar(&pruneSystemCommand.Volume, "volumes", false, "Prune volumes") + +} + +func pruneSystemCmd(c *cliconfig.SystemPruneValues) error { // Prompt for confirmation if --force is not set - if !c.Bool("force") { + if !c.Force { reader := bufio.NewReader(os.Stdin) volumeString := "" - if c.Bool("volumes") { + if c.Volume { volumeString = ` - all volumes not used by at least one container` } @@ -68,7 +68,7 @@ Are you sure you want to continue? [y/N] `, volumeString) } } - runtime, err := adapter.GetRuntime(c) + runtime, err := adapter.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") } @@ -90,7 +90,7 @@ Are you sure you want to continue? [y/N] `, volumeString) // Call prune; if any cids are returned, print them and then // return err in case an error also came up - pruneCids, err := runtime.PruneImages(c.Bool("all")) + pruneCids, err := runtime.PruneImages(c.All) if len(pruneCids) > 0 { fmt.Println("Deleted Images") for _, cid := range pruneCids { |