2017-06-16 17:24:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
rmiDescription = "removes one or more locally stored images."
|
|
|
|
rmiFlags = []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "force, f",
|
|
|
|
Usage: "force removal of the image",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
rmiCommand = cli.Command{
|
|
|
|
Name: "rmi",
|
|
|
|
Usage: "removes one or more images from local storage",
|
|
|
|
Description: rmiDescription,
|
|
|
|
Action: rmiCmd,
|
|
|
|
ArgsUsage: "IMAGE-NAME-OR-ID [...]",
|
|
|
|
Flags: rmiFlags,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func rmiCmd(c *cli.Context) error {
|
2017-09-28 18:44:48 +00:00
|
|
|
if err := validateFlags(c, rmiFlags); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-16 17:24:00 +00:00
|
|
|
|
2017-09-21 19:21:56 +00:00
|
|
|
runtime, err := getRuntime(c)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "could not get runtime")
|
2017-06-16 17:24:00 +00:00
|
|
|
}
|
2017-09-21 19:21:56 +00:00
|
|
|
defer runtime.Shutdown(false)
|
2017-06-16 17:24:00 +00:00
|
|
|
|
|
|
|
args := c.Args()
|
|
|
|
if len(args) == 0 {
|
|
|
|
return errors.Errorf("image name or ID must be specified")
|
|
|
|
}
|
|
|
|
|
2017-09-21 19:21:56 +00:00
|
|
|
for _, arg := range args {
|
|
|
|
image, err := runtime.GetImage(arg)
|
2017-06-16 17:24:00 +00:00
|
|
|
if err != nil {
|
2017-09-21 19:21:56 +00:00
|
|
|
return errors.Wrapf(err, "could not get image %q", arg)
|
2017-06-16 17:24:00 +00:00
|
|
|
}
|
2017-09-21 19:21:56 +00:00
|
|
|
id, err := runtime.RemoveImage(image, c.Bool("force"))
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrapf(err, "error removing image %q", id)
|
2017-06-16 17:24:00 +00:00
|
|
|
}
|
2017-09-21 19:21:56 +00:00
|
|
|
fmt.Printf("%s\n", id)
|
2017-06-16 17:24:00 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|