Convert CLI to urfave v2
Followed the Migration Guide at https://cli.urfave.org/migrate-v1-to-v2/ The major changes not pointed out in the migration guide are: - context.Args() no longer produces a []slice, so context.Args().Slice() in substitued - All cli.Global***** are deprecated (the migration guide is somewhat unclear on this) Signed-off-by: Derek Nola <derek.nola@suse.com> Vendor in urfave cli/v2 Signed-off-by: Derek Nola <derek.nola@suse.com> Fix NewStringSlice calls Signed-off-by: Derek Nola <derek.nola@suse.com>
This commit is contained in:
@@ -24,10 +24,10 @@ import (
|
||||
"github.com/containerd/containerd/v2/core/images/converter"
|
||||
"github.com/containerd/containerd/v2/core/images/converter/uncompress"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var convertCommand = cli.Command{
|
||||
var convertCommand = &cli.Command{
|
||||
Name: "convert",
|
||||
Usage: "Convert an image",
|
||||
ArgsUsage: "[flags] <source_ref> <target_ref>",
|
||||
@@ -40,21 +40,21 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
// generic flags
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "uncompress",
|
||||
Usage: "Convert tar.gz layers to uncompressed tar layers",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "oci",
|
||||
Usage: "Convert Docker media types to OCI media types",
|
||||
},
|
||||
// platform flags
|
||||
cli.StringSliceFlag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "platform",
|
||||
Usage: "Pull content from a specific platform",
|
||||
Value: &cli.StringSlice{},
|
||||
Value: cli.NewStringSlice(),
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "all-platforms",
|
||||
Usage: "Exports content from all platforms",
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/v2/core/images/archive"
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
"github.com/containerd/platforms"
|
||||
)
|
||||
|
||||
var exportCommand = cli.Command{
|
||||
var exportCommand = &cli.Command{
|
||||
Name: "export",
|
||||
Usage: "Export images",
|
||||
ArgsUsage: "[flags] <out> <image> ...",
|
||||
@@ -44,24 +44,24 @@ Use '--platform' to define the output platform.
|
||||
When '--all-platforms' is given all images in a manifest list must be available.
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-manifest-json",
|
||||
Usage: "Do not add Docker compatible manifest.json to archive",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-non-distributable",
|
||||
Usage: "Do not add non-distributable blobs such as Windows layers to archive",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "platform",
|
||||
Usage: "Pull content from a specific platform",
|
||||
Value: &cli.StringSlice{},
|
||||
Value: cli.NewStringSlice(),
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "all-platforms",
|
||||
Usage: "Exports content from all platforms",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "local",
|
||||
Usage: "Run export locally rather than through transfer API",
|
||||
},
|
||||
|
||||
@@ -30,11 +30,11 @@ import (
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Command is the cli command for managing images
|
||||
var Command = cli.Command{
|
||||
var Command = &cli.Command{
|
||||
Name: "images",
|
||||
Aliases: []string{"image", "i"},
|
||||
Usage: "Manage images",
|
||||
@@ -57,21 +57,22 @@ var Command = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var listCommand = cli.Command{
|
||||
var listCommand = &cli.Command{
|
||||
Name: "list",
|
||||
Aliases: []string{"ls"},
|
||||
Usage: "List images known to containerd",
|
||||
ArgsUsage: "[flags] [<filter>, ...]",
|
||||
Description: "list images registered with containerd",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "quiet, q",
|
||||
Usage: "Print only the image refs",
|
||||
&cli.BoolFlag{
|
||||
Name: "quiet",
|
||||
Aliases: []string{"q"},
|
||||
Usage: "Print only the image refs",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
var (
|
||||
filters = context.Args()
|
||||
filters = context.Args().Slice()
|
||||
quiet = context.Bool("quiet")
|
||||
)
|
||||
client, ctx, cancel, err := commands.NewClient(context)
|
||||
@@ -141,15 +142,16 @@ var listCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var setLabelsCommand = cli.Command{
|
||||
var setLabelsCommand = &cli.Command{
|
||||
Name: "label",
|
||||
Usage: "Set and clear labels for an image",
|
||||
ArgsUsage: "[flags] <name> [<key>=<value>, ...]",
|
||||
Description: "set and clear labels for an image",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "replace-all, r",
|
||||
Usage: "Replace all labels",
|
||||
&cli.BoolFlag{
|
||||
Name: "replace-all",
|
||||
Aliases: []string{"r"},
|
||||
Usage: "Replace all labels",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
@@ -200,15 +202,16 @@ var setLabelsCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var checkCommand = cli.Command{
|
||||
var checkCommand = &cli.Command{
|
||||
Name: "check",
|
||||
Usage: "Check existing images to ensure all content is available locally",
|
||||
ArgsUsage: "[flags] [<filter>, ...]",
|
||||
Description: "check existing images to ensure all content is available locally",
|
||||
Flags: append([]cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "quiet, q",
|
||||
Usage: "Print only the ready image refs (fully downloaded and unpacked)",
|
||||
&cli.BoolFlag{
|
||||
Name: "quiet",
|
||||
Aliases: []string{"q"},
|
||||
Usage: "Print only the ready image refs (fully downloaded and unpacked)",
|
||||
},
|
||||
}, commands.SnapshotterFlags...),
|
||||
Action: func(context *cli.Context) error {
|
||||
@@ -224,7 +227,7 @@ var checkCommand = cli.Command{
|
||||
|
||||
var contentStore = client.ContentStore()
|
||||
|
||||
args := []string(context.Args())
|
||||
args := context.Args().Slice()
|
||||
imageList, err := client.ListImages(ctx, args...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed listing images: %w", err)
|
||||
@@ -313,14 +316,14 @@ var checkCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var removeCommand = cli.Command{
|
||||
var removeCommand = &cli.Command{
|
||||
Name: "delete",
|
||||
Aliases: []string{"del", "remove", "rm"},
|
||||
Usage: "Remove one or more images by reference",
|
||||
ArgsUsage: "[flags] <ref> [<ref>, ...]",
|
||||
Description: "remove one or more images by reference",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "sync",
|
||||
Usage: "Synchronously remove image and all associated resources",
|
||||
},
|
||||
@@ -335,7 +338,7 @@ var removeCommand = cli.Command{
|
||||
exitErr error
|
||||
imageStore = client.ImageService()
|
||||
)
|
||||
for i, target := range context.Args() {
|
||||
for i, target := range context.Args().Slice() {
|
||||
var opts []images.DeleteOpt
|
||||
if context.Bool("sync") && i == context.NArg()-1 {
|
||||
opts = append(opts, images.SynchronousDelete())
|
||||
@@ -359,11 +362,11 @@ var removeCommand = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var pruneCommand = cli.Command{
|
||||
var pruneCommand = &cli.Command{
|
||||
Name: "prune",
|
||||
Usage: "Remove unused images",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "all", // TODO: add more filters
|
||||
Usage: "Remove all unused images, not just dangling ones (if all is not specified no images will be pruned)",
|
||||
},
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"time"
|
||||
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
containerd "github.com/containerd/containerd/v2/client"
|
||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||
@@ -35,7 +35,7 @@ import (
|
||||
"github.com/containerd/platforms"
|
||||
)
|
||||
|
||||
var importCommand = cli.Command{
|
||||
var importCommand = &cli.Command{
|
||||
Name: "import",
|
||||
Usage: "Import images",
|
||||
ArgsUsage: "[flags] <in>",
|
||||
@@ -57,44 +57,44 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb
|
||||
"foo/bar:latest" and "foo/bar@sha256:deadbeef" images in the containerd store.
|
||||
`,
|
||||
Flags: append([]cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "base-name",
|
||||
Value: "",
|
||||
Usage: "Base image name for added images, when provided only images with this name prefix are imported",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "digests",
|
||||
Usage: "Whether to create digest images (default: false)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-digest-for-named",
|
||||
Usage: "Skip applying --digests option to images named in the importing tar (use it in conjunction with --digests)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "index-name",
|
||||
Usage: "Image name to keep index as, by default index is discarded",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "all-platforms",
|
||||
Usage: "Imports content for all platforms, false by default",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "platform",
|
||||
Usage: "Imports content for specific platform",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "no-unpack",
|
||||
Usage: "Skip unpacking the images, cannot be used with --discard-unpacked-layers, false by default",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "local",
|
||||
Usage: "Run import locally rather than through transfer API",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "compress-blobs",
|
||||
Usage: "Compress uncompressed blobs when creating manifest (Docker format only)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "discard-unpacked-layers",
|
||||
Usage: "Allow the garbage collector to clean layers up from the content store after unpacking, cannot be used with --no-unpack, false by default",
|
||||
},
|
||||
|
||||
@@ -21,17 +21,17 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/v2/pkg/display"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var inspectCommand = cli.Command{
|
||||
var inspectCommand = &cli.Command{
|
||||
Name: "inspect",
|
||||
Aliases: []string{"i"},
|
||||
Usage: "inspect an image",
|
||||
ArgsUsage: "<image> [flags]",
|
||||
Description: `Inspect an image`,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "content",
|
||||
Usage: "Show JSON content",
|
||||
},
|
||||
|
||||
@@ -28,10 +28,10 @@ import (
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var mountCommand = cli.Command{
|
||||
var mountCommand = &cli.Command{
|
||||
Name: "mount",
|
||||
Usage: "Mount an image to a target path",
|
||||
ArgsUsage: "[flags] <ref> <target>",
|
||||
@@ -40,11 +40,11 @@ var mountCommand = cli.Command{
|
||||
When you are done, use the unmount command.
|
||||
`,
|
||||
Flags: append(append(commands.RegistryFlags, append(commands.SnapshotterFlags, commands.LabelFlag)...),
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "rw",
|
||||
Usage: "Enable write support on the mount",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "platform",
|
||||
Usage: "Mount the image for the specified platform",
|
||||
Value: platforms.DefaultString(),
|
||||
|
||||
@@ -36,10 +36,10 @@ import (
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var pullCommand = cli.Command{
|
||||
var pullCommand = &cli.Command{
|
||||
Name: "pull",
|
||||
Usage: "Pull an image from a remote",
|
||||
ArgsUsage: "[flags] <ref>",
|
||||
@@ -53,33 +53,33 @@ command. As part of this process, we do the following:
|
||||
3. Register metadata for the image.
|
||||
`,
|
||||
Flags: append(append(commands.RegistryFlags, append(commands.SnapshotterFlags, commands.LabelFlag)...),
|
||||
cli.StringSliceFlag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "platform",
|
||||
Usage: "Pull content from a specific platform",
|
||||
Value: &cli.StringSlice{},
|
||||
Value: cli.NewStringSlice(),
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "all-platforms",
|
||||
Usage: "Pull content and metadata from all platforms",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "all-metadata",
|
||||
Usage: "(Deprecated: use skip-metadata) Pull metadata for all platforms",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-metadata",
|
||||
Usage: "Skips metadata for unused platforms (Image may be unable to be pushed without metadata)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "print-chainid",
|
||||
Usage: "Print the resulting image's chain ID",
|
||||
},
|
||||
cli.IntFlag{
|
||||
&cli.IntFlag{
|
||||
Name: "max-concurrent-downloads",
|
||||
Usage: "Set the max concurrent downloads for each pull",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "local",
|
||||
Usage: "Fetch content from local client rather than using transfer service",
|
||||
},
|
||||
|
||||
@@ -40,11 +40,11 @@ import (
|
||||
"github.com/containerd/platforms"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var pushCommand = cli.Command{
|
||||
var pushCommand = &cli.Command{
|
||||
Name: "push",
|
||||
Usage: "Push an image to a remote",
|
||||
ArgsUsage: "[flags] <remote> [<local>]",
|
||||
@@ -57,24 +57,24 @@ var pushCommand = cli.Command{
|
||||
creating the associated configuration, and creating the manifest
|
||||
which references those resources.
|
||||
`,
|
||||
Flags: append(commands.RegistryFlags, cli.StringFlag{
|
||||
Flags: append(commands.RegistryFlags, &cli.StringFlag{
|
||||
Name: "manifest",
|
||||
Usage: "Digest of manifest",
|
||||
}, cli.StringFlag{
|
||||
}, &cli.StringFlag{
|
||||
Name: "manifest-type",
|
||||
Usage: "Media type of manifest digest",
|
||||
Value: ocispec.MediaTypeImageManifest,
|
||||
}, cli.StringSliceFlag{
|
||||
}, &cli.StringSliceFlag{
|
||||
Name: "platform",
|
||||
Usage: "Push content from a specific platform",
|
||||
Value: &cli.StringSlice{},
|
||||
}, cli.IntFlag{
|
||||
Value: cli.NewStringSlice(),
|
||||
}, &cli.IntFlag{
|
||||
Name: "max-concurrent-uploaded-layers",
|
||||
Usage: "Set the max concurrent uploaded layers for each push",
|
||||
}, cli.BoolFlag{
|
||||
}, &cli.BoolFlag{
|
||||
Name: "local",
|
||||
Usage: "Push content from local client rather than using transfer service",
|
||||
}, cli.BoolFlag{
|
||||
}, &cli.BoolFlag{
|
||||
Name: "allow-non-distributable-blobs",
|
||||
Usage: "Allow pushing blobs that are marked as non-distributable",
|
||||
}),
|
||||
@@ -82,7 +82,7 @@ var pushCommand = cli.Command{
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
local = context.Args().Get(1)
|
||||
debug = context.GlobalBool("debug")
|
||||
debug = context.Bool("debug")
|
||||
desc ocispec.Descriptor
|
||||
)
|
||||
if ref == "" {
|
||||
|
||||
@@ -19,7 +19,7 @@ package images
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||
"github.com/containerd/containerd/v2/core/transfer/image"
|
||||
@@ -27,21 +27,21 @@ import (
|
||||
"github.com/distribution/reference"
|
||||
)
|
||||
|
||||
var tagCommand = cli.Command{
|
||||
var tagCommand = &cli.Command{
|
||||
Name: "tag",
|
||||
Usage: "Tag an image",
|
||||
ArgsUsage: "[flags] <source_ref> <target_ref> [<target_ref>, ...]",
|
||||
Description: `Tag an image for use in containerd.`,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "force",
|
||||
Usage: "Force target_ref to be created, regardless if it already exists",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "local",
|
||||
Usage: "Run tag locally rather than through transfer API",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-reference-check",
|
||||
Usage: "Skip the strict check for reference names",
|
||||
},
|
||||
@@ -64,7 +64,7 @@ var tagCommand = cli.Command{
|
||||
defer cancel()
|
||||
|
||||
if !context.Bool("local") {
|
||||
for _, targetRef := range context.Args()[1:] {
|
||||
for _, targetRef := range context.Args().Slice()[1:] {
|
||||
if !context.Bool("skip-reference-check") {
|
||||
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
||||
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
||||
@@ -91,7 +91,7 @@ var tagCommand = cli.Command{
|
||||
return err
|
||||
}
|
||||
// Support multiple references for one command run
|
||||
for _, targetRef := range context.Args()[1:] {
|
||||
for _, targetRef := range context.Args().Slice()[1:] {
|
||||
if !context.Bool("skip-reference-check") {
|
||||
if _, err := reference.ParseAnyReference(targetRef); err != nil {
|
||||
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
||||
|
||||
@@ -23,16 +23,16 @@ import (
|
||||
"github.com/containerd/containerd/v2/core/leases"
|
||||
"github.com/containerd/containerd/v2/core/mount"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var unmountCommand = cli.Command{
|
||||
var unmountCommand = &cli.Command{
|
||||
Name: "unmount",
|
||||
Usage: "Unmount the image from the target",
|
||||
ArgsUsage: "[flags] <target>",
|
||||
Description: "Unmount the image rootfs from the specified target.",
|
||||
Flags: append(append(commands.RegistryFlags, append(commands.SnapshotterFlags, commands.LabelFlag)...),
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "rm",
|
||||
Usage: "Remove the snapshot after a successful unmount",
|
||||
},
|
||||
|
||||
@@ -27,10 +27,10 @@ import (
|
||||
"github.com/containerd/containerd/v2/pkg/progress"
|
||||
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var usageCommand = cli.Command{
|
||||
var usageCommand = &cli.Command{
|
||||
Name: "usage",
|
||||
Usage: "Display usage of snapshots for a given image ref",
|
||||
ArgsUsage: "[flags] <ref>",
|
||||
|
||||
Reference in New Issue
Block a user