cmd: don't alias context package, and use cliContext for cli.Context
Unfortunately, this is a rather large diff, but perhaps worth a one-time "rip off the bandaid" for v2. This patch removes the use of "gocontext" as alias for stdLib's "context", and uses "cliContext" for uses of cli.context. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
package snapshots
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -67,18 +67,18 @@ var listCommand = &cli.Command{
|
||||
Name: "list",
|
||||
Aliases: []string{"ls"},
|
||||
Usage: "List snapshots",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
var (
|
||||
snapshotter = client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter = client.SnapshotService(cliContext.String("snapshotter"))
|
||||
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
||||
)
|
||||
fmt.Fprintln(tw, "KEY\tPARENT\tKIND\t")
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
||||
if err := snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\t\n",
|
||||
info.Name,
|
||||
info.Parent,
|
||||
@@ -111,15 +111,15 @@ var diffCommand = &cli.Command{
|
||||
Usage: "Keep diff content. up to creator to delete it.",
|
||||
},
|
||||
}, commands.LabelFlag),
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var (
|
||||
idA = context.Args().First()
|
||||
idB = context.Args().Get(1)
|
||||
idA = cliContext.Args().First()
|
||||
idB = cliContext.Args().Get(1)
|
||||
)
|
||||
if idA == "" {
|
||||
return errors.New("snapshot id must be provided")
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -132,15 +132,15 @@ var diffCommand = &cli.Command{
|
||||
defer done(ctx)
|
||||
|
||||
var desc ocispec.Descriptor
|
||||
labels := commands.LabelArgs(context.StringSlice("label"))
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
labels := commands.LabelArgs(cliContext.StringSlice("label"))
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
|
||||
if context.Bool("keep") {
|
||||
if cliContext.Bool("keep") {
|
||||
labels["containerd.io/gc.root"] = time.Now().UTC().Format(time.RFC3339)
|
||||
}
|
||||
opts := []diff.Opt{
|
||||
diff.WithMediaType(context.String("media-type")),
|
||||
diff.WithReference(context.String("ref")),
|
||||
diff.WithMediaType(cliContext.String("media-type")),
|
||||
diff.WithReference(cliContext.String("ref")),
|
||||
diff.WithLabels(labels),
|
||||
}
|
||||
// SOURCE_DATE_EPOCH is propagated via the ctx, so no need to specify diff.WithSourceDateEpoch here
|
||||
@@ -172,7 +172,7 @@ var diffCommand = &cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func withMounts(ctx gocontext.Context, id string, sn snapshots.Snapshotter, f func(mounts []mount.Mount) (ocispec.Descriptor, error)) (ocispec.Descriptor, error) {
|
||||
func withMounts(ctx context.Context, id string, sn snapshots.Snapshotter, f func(mounts []mount.Mount) (ocispec.Descriptor, error)) (ocispec.Descriptor, error) {
|
||||
var mounts []mount.Mount
|
||||
info, err := sn.Stat(ctx, id)
|
||||
if err != nil {
|
||||
@@ -204,9 +204,9 @@ var usageCommand = &cli.Command{
|
||||
Usage: "Display size in bytes",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
var displaySize func(int64) string
|
||||
if context.Bool("b") {
|
||||
if cliContext.Bool("b") {
|
||||
displaySize = func(s int64) string {
|
||||
return strconv.FormatInt(s, 10)
|
||||
}
|
||||
@@ -215,18 +215,18 @@ var usageCommand = &cli.Command{
|
||||
return progress.Bytes(s).String()
|
||||
}
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
var (
|
||||
snapshotter = client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter = client.SnapshotService(cliContext.String("snapshotter"))
|
||||
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
|
||||
)
|
||||
fmt.Fprintln(tw, "KEY\tSIZE\tINODES\t")
|
||||
if context.NArg() == 0 {
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
||||
if cliContext.NArg() == 0 {
|
||||
if err := snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||
usage, err := snapshotter.Usage(ctx, info.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -237,7 +237,7 @@ var usageCommand = &cli.Command{
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
for _, id := range context.Args().Slice() {
|
||||
for _, id := range cliContext.Args().Slice() {
|
||||
usage, err := snapshotter.Usage(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -255,14 +255,14 @@ var removeCommand = &cli.Command{
|
||||
Aliases: []string{"del", "remove", "rm"},
|
||||
ArgsUsage: "<key> [<key>, ...]",
|
||||
Usage: "Remove snapshots",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
for _, key := range context.Args().Slice() {
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
for _, key := range cliContext.Args().Slice() {
|
||||
err = snapshotter.Remove(ctx, key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove %q: %w", key, err)
|
||||
@@ -288,22 +288,22 @@ var prepareCommand = &cli.Command{
|
||||
Usage: "Print out snapshot mounts as JSON",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
if narg := context.NArg(); narg < 1 || narg > 2 {
|
||||
return cli.ShowSubcommandHelp(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
if narg := cliContext.NArg(); narg < 1 || narg > 2 {
|
||||
return cli.ShowSubcommandHelp(cliContext)
|
||||
}
|
||||
var (
|
||||
target = context.String("target")
|
||||
key = context.Args().Get(0)
|
||||
parent = context.Args().Get(1)
|
||||
target = cliContext.String("target")
|
||||
key = cliContext.Args().Get(0)
|
||||
parent = cliContext.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
labels := map[string]string{
|
||||
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
@@ -317,7 +317,7 @@ var prepareCommand = &cli.Command{
|
||||
printMounts(target, mounts)
|
||||
}
|
||||
|
||||
if context.Bool("mounts") {
|
||||
if cliContext.Bool("mounts") {
|
||||
commands.PrintAsJSON(mounts)
|
||||
}
|
||||
|
||||
@@ -340,22 +340,22 @@ var viewCommand = &cli.Command{
|
||||
Usage: "Print out snapshot mounts as JSON",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
if narg := context.NArg(); narg < 1 || narg > 2 {
|
||||
return cli.ShowSubcommandHelp(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
if narg := cliContext.NArg(); narg < 1 || narg > 2 {
|
||||
return cli.ShowSubcommandHelp(cliContext)
|
||||
}
|
||||
var (
|
||||
target = context.String("target")
|
||||
key = context.Args().Get(0)
|
||||
parent = context.Args().Get(1)
|
||||
target = cliContext.String("target")
|
||||
key = cliContext.Args().Get(0)
|
||||
parent = cliContext.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
mounts, err := snapshotter.View(ctx, key, parent)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -365,7 +365,7 @@ var viewCommand = &cli.Command{
|
||||
printMounts(target, mounts)
|
||||
}
|
||||
|
||||
if context.Bool("mounts") {
|
||||
if cliContext.Bool("mounts") {
|
||||
commands.PrintAsJSON(mounts)
|
||||
}
|
||||
|
||||
@@ -378,20 +378,20 @@ var mountCommand = &cli.Command{
|
||||
Aliases: []string{"m", "mount"},
|
||||
Usage: "Mount gets mount commands for the snapshots",
|
||||
ArgsUsage: "<target> <key>",
|
||||
Action: func(context *cli.Context) error {
|
||||
if context.NArg() != 2 {
|
||||
return cli.ShowSubcommandHelp(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
if cliContext.NArg() != 2 {
|
||||
return cli.ShowSubcommandHelp(cliContext)
|
||||
}
|
||||
var (
|
||||
target = context.Args().Get(0)
|
||||
key = context.Args().Get(1)
|
||||
target = cliContext.Args().Get(0)
|
||||
key = cliContext.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
mounts, err := snapshotter.Mounts(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -407,20 +407,20 @@ var commitCommand = &cli.Command{
|
||||
Name: "commit",
|
||||
Usage: "Commit an active snapshot into the provided name",
|
||||
ArgsUsage: "<key> <active>",
|
||||
Action: func(context *cli.Context) error {
|
||||
if context.NArg() != 2 {
|
||||
return cli.ShowSubcommandHelp(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
if cliContext.NArg() != 2 {
|
||||
return cli.ShowSubcommandHelp(cliContext)
|
||||
}
|
||||
var (
|
||||
key = context.Args().Get(0)
|
||||
active = context.Args().Get(1)
|
||||
key = cliContext.Args().Get(0)
|
||||
active = cliContext.Args().Get(1)
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
labels := map[string]string{
|
||||
"containerd.io/gc.root": time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
@@ -431,18 +431,18 @@ var commitCommand = &cli.Command{
|
||||
var treeCommand = &cli.Command{
|
||||
Name: "tree",
|
||||
Usage: "Display tree view of snapshot branches",
|
||||
Action: func(context *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
var (
|
||||
snapshotter = client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter = client.SnapshotService(cliContext.String("snapshotter"))
|
||||
tree = newSnapshotTree()
|
||||
)
|
||||
|
||||
if err := snapshotter.Walk(ctx, func(ctx gocontext.Context, info snapshots.Info) error {
|
||||
if err := snapshotter.Walk(ctx, func(ctx context.Context, info snapshots.Info) error {
|
||||
// Get or create node and add node details
|
||||
tree.add(info)
|
||||
return nil
|
||||
@@ -460,18 +460,18 @@ var infoCommand = &cli.Command{
|
||||
Name: "info",
|
||||
Usage: "Get info about a snapshot",
|
||||
ArgsUsage: "<key>",
|
||||
Action: func(context *cli.Context) error {
|
||||
if context.NArg() != 1 {
|
||||
return cli.ShowSubcommandHelp(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
if cliContext.NArg() != 1 {
|
||||
return cli.ShowSubcommandHelp(cliContext)
|
||||
}
|
||||
|
||||
key := context.Args().Get(0)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
key := cliContext.Args().Get(0)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
info, err := snapshotter.Stat(ctx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -488,15 +488,15 @@ var setLabelCommand = &cli.Command{
|
||||
Usage: "Add labels to content",
|
||||
ArgsUsage: "<name> [<label>=<value> ...]",
|
||||
Description: "labels snapshots in the snapshotter",
|
||||
Action: func(context *cli.Context) error {
|
||||
key, labels := commands.ObjectWithLabelArgs(context)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
key, labels := commands.ObjectWithLabelArgs(cliContext)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
snapshotter := client.SnapshotService(context.String("snapshotter"))
|
||||
snapshotter := client.SnapshotService(cliContext.String("snapshotter"))
|
||||
|
||||
info := snapshots.Info{
|
||||
Name: key,
|
||||
@@ -537,12 +537,12 @@ var unpackCommand = &cli.Command{
|
||||
Usage: "Unpack applies layers from a manifest to a snapshot",
|
||||
ArgsUsage: "[flags] <digest>",
|
||||
Flags: commands.SnapshotterFlags,
|
||||
Action: func(context *cli.Context) error {
|
||||
dgst, err := digest.Parse(context.Args().First())
|
||||
Action: func(cliContext *cli.Context) error {
|
||||
dgst, err := digest.Parse(cliContext.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
client, ctx, cancel, err := commands.NewClient(cliContext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -557,7 +557,7 @@ var unpackCommand = &cli.Command{
|
||||
for _, image := range images {
|
||||
if image.Target().Digest == dgst {
|
||||
fmt.Printf("unpacking %s (%s)...", dgst, image.Target().MediaType)
|
||||
if err := image.Unpack(ctx, context.String("snapshotter")); err != nil {
|
||||
if err := image.Unpack(ctx, cliContext.String("snapshotter")); err != nil {
|
||||
fmt.Println()
|
||||
return err
|
||||
}
|
||||
@@ -570,7 +570,7 @@ var unpackCommand = &cli.Command{
|
||||
return errors.New("manifest not found")
|
||||
}
|
||||
// TODO: Get rootfs from Image
|
||||
//log.G(ctx).Infof("chain ID: %s", chainID.String())
|
||||
// log.G(ctx).Infof("chain ID: %s", chainID.String())
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user