diff options
author | Kunal Kushwaha <kunal.kushwaha@gmail.com> | 2019-11-12 13:50:35 +0900 |
---|---|---|
committer | Kunal Kushwaha <kunal.kushwaha@gmail.com> | 2019-11-12 14:13:49 +0900 |
commit | 472a721bdd5007fe4b68a982ac5f979bec40a3d1 (patch) | |
tree | 34925f90cde03e3a7d025c4c39f5634e32f9d69d /cmd/podman/images_prune.go | |
parent | b713e5371fa8767067bd2c329a3744ea593b2ade (diff) | |
download | podman-472a721bdd5007fe4b68a982ac5f979bec40a3d1.tar.gz podman-472a721bdd5007fe4b68a982ac5f979bec40a3d1.tar.bz2 podman-472a721bdd5007fe4b68a982ac5f979bec40a3d1.zip |
warning added before image prune command
Warning message added before executing image prune
Added a force option, to execute without user input.
Signed-off-by: Kunal Kushwaha <kunal.kushwaha@gmail.com>
Diffstat (limited to 'cmd/podman/images_prune.go')
-rw-r--r-- | cmd/podman/images_prune.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cmd/podman/images_prune.go b/cmd/podman/images_prune.go index 5745edd6b..9c0a18c41 100644 --- a/cmd/podman/images_prune.go +++ b/cmd/podman/images_prune.go @@ -1,7 +1,10 @@ package main import ( + "bufio" "fmt" + "os" + "strings" "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/pkg/adapter" @@ -34,9 +37,23 @@ func init() { pruneImagesCommand.SetUsageTemplate(UsageTemplate()) flags := pruneImagesCommand.Flags() flags.BoolVarP(&pruneImagesCommand.All, "all", "a", false, "Remove all unused images, not just dangling ones") + flags.BoolVarP(&pruneImagesCommand.Force, "force", "f", false, "Do not prompt for confirmation") } func pruneImagesCmd(c *cliconfig.PruneImagesValues) error { + if !c.Force { + reader := bufio.NewReader(os.Stdin) + fmt.Printf(` +WARNING! This will remove all dangling images. +Are you sure you want to continue? [y/N] `) + ans, err := reader.ReadString('\n') + if err != nil { + return errors.Wrapf(err, "error reading input") + } + if strings.ToLower(ans)[0] != 'y' { + return nil + } + } runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") |