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:
		@@ -27,11 +27,11 @@ import (
 | 
			
		||||
	"github.com/containerd/containerd/v2/cmd/ctr/commands"
 | 
			
		||||
	"github.com/containerd/errdefs"
 | 
			
		||||
	"github.com/containerd/log"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Command is the cli command for managing namespaces
 | 
			
		||||
var Command = cli.Command{
 | 
			
		||||
var Command = &cli.Command{
 | 
			
		||||
	Name:    "namespaces",
 | 
			
		||||
	Aliases: []string{"namespace", "ns"},
 | 
			
		||||
	Usage:   "Manage namespaces",
 | 
			
		||||
@@ -43,7 +43,7 @@ var Command = cli.Command{
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var createCommand = cli.Command{
 | 
			
		||||
var createCommand = &cli.Command{
 | 
			
		||||
	Name:        "create",
 | 
			
		||||
	Aliases:     []string{"c"},
 | 
			
		||||
	Usage:       "Create a new namespace",
 | 
			
		||||
@@ -64,7 +64,7 @@ var createCommand = cli.Command{
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var setLabelsCommand = cli.Command{
 | 
			
		||||
var setLabelsCommand = &cli.Command{
 | 
			
		||||
	Name:        "label",
 | 
			
		||||
	Usage:       "Set and clear labels for a namespace",
 | 
			
		||||
	ArgsUsage:   "<name> [<key>=<value>, ...]",
 | 
			
		||||
@@ -89,16 +89,17 @@ var setLabelsCommand = cli.Command{
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var listCommand = cli.Command{
 | 
			
		||||
var listCommand = &cli.Command{
 | 
			
		||||
	Name:        "list",
 | 
			
		||||
	Aliases:     []string{"ls"},
 | 
			
		||||
	Usage:       "List namespaces",
 | 
			
		||||
	ArgsUsage:   "[flags]",
 | 
			
		||||
	Description: "list namespaces",
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		cli.BoolFlag{
 | 
			
		||||
			Name:  "quiet, q",
 | 
			
		||||
			Usage: "Print only the namespace name",
 | 
			
		||||
		&cli.BoolFlag{
 | 
			
		||||
			Name:    "quiet",
 | 
			
		||||
			Aliases: []string{"q"},
 | 
			
		||||
			Usage:   "Print only the namespace name",
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(context *cli.Context) error {
 | 
			
		||||
@@ -141,16 +142,17 @@ var listCommand = cli.Command{
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var removeCommand = cli.Command{
 | 
			
		||||
var removeCommand = &cli.Command{
 | 
			
		||||
	Name:        "remove",
 | 
			
		||||
	Aliases:     []string{"rm"},
 | 
			
		||||
	Usage:       "Remove one or more namespaces",
 | 
			
		||||
	ArgsUsage:   "<name> [<name>, ...]",
 | 
			
		||||
	Description: "remove one or more namespaces. for now, the namespace must be empty",
 | 
			
		||||
	Flags: []cli.Flag{
 | 
			
		||||
		cli.BoolFlag{
 | 
			
		||||
			Name:  "cgroup,c",
 | 
			
		||||
			Usage: "Delete the namespace's cgroup",
 | 
			
		||||
		&cli.BoolFlag{
 | 
			
		||||
			Name:    "cgroup",
 | 
			
		||||
			Aliases: []string{"c"},
 | 
			
		||||
			Usage:   "Delete the namespace's cgroup",
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	Action: func(context *cli.Context) error {
 | 
			
		||||
@@ -163,7 +165,7 @@ var removeCommand = cli.Command{
 | 
			
		||||
 | 
			
		||||
		opts := deleteOpts(context)
 | 
			
		||||
		namespaces := client.NamespaceService()
 | 
			
		||||
		for _, target := range context.Args() {
 | 
			
		||||
		for _, target := range context.Args().Slice() {
 | 
			
		||||
			if err := namespaces.Delete(ctx, target, opts...); err != nil {
 | 
			
		||||
				if !errdefs.IsNotFound(err) {
 | 
			
		||||
					if exitErr == nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ package namespaces
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/containerd/containerd/v2/core/runtime/opts"
 | 
			
		||||
	"github.com/containerd/containerd/v2/pkg/namespaces"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func deleteOpts(context *cli.Context) []namespaces.DeleteOpts {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ package namespaces
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/containerd/containerd/v2/pkg/namespaces"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
	"github.com/urfave/cli/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func deleteOpts(context *cli.Context) []namespaces.DeleteOpts {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user