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:
Derek Nola
2024-02-12 10:51:13 -08:00
parent d4d228926c
commit 132485adb0
149 changed files with 11041 additions and 4693 deletions

View File

@@ -26,11 +26,11 @@ import (
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/containerd/containerd/v2/core/leases"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
// Command is the cli command for managing content
var Command = cli.Command{
var Command = &cli.Command{
Name: "leases",
Usage: "Manage leases",
Subcommands: cli.Commands{
@@ -40,7 +40,7 @@ var Command = cli.Command{
},
}
var listCommand = cli.Command{
var listCommand = &cli.Command{
Name: "list",
Aliases: []string{"ls"},
@@ -48,14 +48,15 @@ var listCommand = cli.Command{
ArgsUsage: "[flags] <filter>",
Description: "list active leases by containerd",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "Print only the blob digest",
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "Print only the blob digest",
},
},
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)
@@ -99,24 +100,25 @@ var listCommand = cli.Command{
},
}
var createCommand = cli.Command{
var createCommand = &cli.Command{
Name: "create",
Usage: "Create lease",
ArgsUsage: "[flags] <label>=<value> ...",
Description: "create a new lease",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "id",
Usage: "Set the id for the lease, will be generated by default",
},
cli.DurationFlag{
Name: "expires, x",
Usage: "Expiration of lease (0 value will not expire)",
Value: 24 * time.Hour,
&cli.DurationFlag{
Name: "expires",
Aliases: []string{"x"},
Usage: "Expiration of lease (0 value will not expire)",
Value: 24 * time.Hour,
},
},
Action: func(context *cli.Context) error {
var labelstr = context.Args()
var labelstr = context.Args().Slice()
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
return err
@@ -152,20 +154,20 @@ var createCommand = cli.Command{
},
}
var deleteCommand = cli.Command{
var deleteCommand = &cli.Command{
Name: "delete",
Aliases: []string{"del", "remove", "rm"},
Usage: "Delete a lease",
ArgsUsage: "[flags] <lease id> ...",
Description: "delete a lease",
Flags: []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "sync",
Usage: "Synchronously remove leases and all unreferenced resources",
},
},
Action: func(context *cli.Context) error {
var lids = context.Args()
var lids = context.Args().Slice()
if len(lids) == 0 {
return cli.ShowSubcommandHelp(context)
}