From de632b1084b5a2de104d08af277785724bbd3beb Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Fri, 23 Jun 2017 18:24:46 -0700 Subject: [PATCH] ctr: add remove subcommand to snapshot Signed-off-by: Kenfe-Mickael Laventure --- cmd/ctr/snapshot.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/ctr/snapshot.go b/cmd/ctr/snapshot.go index 5ae6ebb09..386269d44 100644 --- a/cmd/ctr/snapshot.go +++ b/cmd/ctr/snapshot.go @@ -2,7 +2,6 @@ package main import ( "context" - "errors" "fmt" "os" "text/tabwriter" @@ -10,6 +9,7 @@ import ( "github.com/containerd/containerd/progress" "github.com/containerd/containerd/rootfs" "github.com/containerd/containerd/snapshot" + "github.com/pkg/errors" "github.com/urfave/cli" ) @@ -20,6 +20,7 @@ var snapshotCommand = cli.Command{ archiveSnapshotCommand, listSnapshotCommand, usageSnapshotCommand, + removeSnapshotCommand, }, } @@ -165,3 +166,30 @@ var usageSnapshotCommand = cli.Command{ return tw.Flush() }, } + +var removeSnapshotCommand = cli.Command{ + Name: "remove", + Aliases: []string{"rm"}, + ArgsUsage: "id [id] ...", + Usage: "remove snapshots", + Action: func(clicontext *cli.Context) error { + ctx, cancel := appContext(clicontext) + defer cancel() + + client, err := newClient(clicontext) + if err != nil { + return err + } + + snapshotter := client.SnapshotService() + + for _, id := range clicontext.Args() { + err = snapshotter.Remove(ctx, id) + if err != nil { + return errors.Wrapf(err, "failed to remove %q", id) + } + } + + return nil + }, +}