cmd/ctr: add prepare subcommand to snapshot

This changeset adds `prepare` subcommand to `ctr snapshot` and removes
`prepare` from `dist rootfs` to keep the basic snapshot operation commands
together.

Signed-off-by: Sunny Gogoi <me@darkowlzz.space>
This commit is contained in:
Sunny Gogoi
2017-07-11 21:30:40 +05:30
parent 13f90e95a7
commit 2c1b54f573
2 changed files with 44 additions and 43 deletions

43
cmd/dist/rootfs.go vendored
View File

@@ -3,8 +3,6 @@ package main
import (
"errors"
"fmt"
"os"
"strings"
"github.com/containerd/containerd/log"
digest "github.com/opencontainers/go-digest"
@@ -16,7 +14,6 @@ var rootfsCommand = cli.Command{
Usage: "rootfs setups a rootfs",
Subcommands: []cli.Command{
rootfsUnpackCommand,
rootfsPrepareCommand,
},
}
@@ -71,43 +68,3 @@ var rootfsUnpackCommand = cli.Command{
return nil
},
}
var rootfsPrepareCommand = cli.Command{
Name: "prepare",
Usage: "prepare gets mount commands for digest",
ArgsUsage: "[flags] <digest> <target>",
Flags: []cli.Flag{},
Action: func(clicontext *cli.Context) error {
ctx, cancel := appContext(clicontext)
defer cancel()
if clicontext.NArg() != 2 {
return cli.ShowSubcommandHelp(clicontext)
}
dgst, err := digest.Parse(clicontext.Args().Get(0))
if err != nil {
return err
}
target := clicontext.Args().Get(1)
log.G(ctx).Infof("preparing mounts %s", dgst.String())
client, err := getClient(clicontext)
if err != nil {
return err
}
snapshotter := client.SnapshotService()
mounts, err := snapshotter.Prepare(ctx, target, dgst.String())
if err != nil {
return err
}
for _, m := range mounts {
fmt.Fprintf(os.Stdout, "mount -t %s %s %s -o %s\n", m.Type, m.Source, target, strings.Join(m.Options, ","))
}
return nil
},
}