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

@@ -21,10 +21,10 @@ import (
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/log"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var attachCommand = cli.Command{
var attachCommand = &cli.Command{
Name: "attach",
Usage: "Attach to the IO of a running container",
ArgsUsage: "CONTAINER",
@@ -79,7 +79,7 @@ var attachCommand = cli.Command{
return err
}
if code != 0 {
return cli.NewExitError("", int(code))
return cli.Exit("", int(code))
}
return nil
},

View File

@@ -23,23 +23,23 @@ import (
containerd "github.com/containerd/containerd/v2/client"
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/containerd/containerd/v2/core/runtime/v2/runc/options"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var checkpointCommand = cli.Command{
var checkpointCommand = &cli.Command{
Name: "checkpoint",
Usage: "Checkpoint a container",
ArgsUsage: "[flags] CONTAINER",
Flags: []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "exit",
Usage: "Stop the container after the checkpoint",
},
cli.StringFlag{
&cli.StringFlag{
Name: "image-path",
Usage: "Path to criu image files",
},
cli.StringFlag{
&cli.StringFlag{
Name: "work-path",
Usage: "Path to criu work files and logs",
},

View File

@@ -23,20 +23,21 @@ import (
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/log"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var deleteCommand = cli.Command{
var deleteCommand = &cli.Command{
Name: "delete",
Usage: "Delete one or more tasks",
ArgsUsage: "CONTAINER [CONTAINER, ...]",
Aliases: []string{"del", "remove", "rm"},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force delete task process",
&cli.BoolFlag{
Name: "force",
Aliases: []string{"f"},
Usage: "Force delete task process",
},
cli.StringFlag{
&cli.StringFlag{
Name: "exec-id",
Usage: "Process ID to kill",
},
@@ -70,10 +71,10 @@ var deleteCommand = cli.Command{
return err
}
if ec := status.ExitCode(); ec != 0 {
return cli.NewExitError("", int(ec))
return cli.Exit("", int(ec))
}
} else {
for _, target := range context.Args() {
for _, target := range context.Args().Slice() {
task, err := loadTask(ctx, client, target)
if err != nil {
if exitErr == nil {

View File

@@ -28,41 +28,42 @@ import (
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/containerd/log"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var execCommand = cli.Command{
Name: "exec",
Usage: "Execute additional processes in an existing container",
ArgsUsage: "[flags] CONTAINER CMD [ARG...]",
SkipArgReorder: true,
var execCommand = &cli.Command{
Name: "exec",
Usage: "Execute additional processes in an existing container",
ArgsUsage: "[flags] CONTAINER CMD [ARG...]",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "cwd",
Usage: "Working directory of the new process",
},
cli.BoolFlag{
Name: "tty,t",
Usage: "Allocate a TTY for the container",
&cli.BoolFlag{
Name: "tty",
Aliases: []string{"t"},
Usage: "Allocate a TTY for the container",
},
cli.BoolFlag{
Name: "detach,d",
Usage: "Detach from the task after it has started execution",
&cli.BoolFlag{
Name: "detach",
Aliases: []string{"d"},
Usage: "Detach from the task after it has started execution",
},
cli.StringFlag{
&cli.StringFlag{
Name: "exec-id",
Required: true,
Usage: "Exec specific id for the process",
},
cli.StringFlag{
&cli.StringFlag{
Name: "fifo-dir",
Usage: "Directory used for storing IO FIFOs",
},
cli.StringFlag{
&cli.StringFlag{
Name: "log-uri",
Usage: "Log uri for custom shim logging",
},
cli.StringFlag{
&cli.StringFlag{
Name: "user",
Usage: "User id or name",
},
@@ -186,7 +187,7 @@ var execCommand = cli.Command{
return err
}
if code != 0 {
return cli.NewExitError("", int(code))
return cli.Exit("", int(code))
}
return nil
},

View File

@@ -27,7 +27,7 @@ import (
"github.com/containerd/log"
"github.com/containerd/typeurl/v2"
"github.com/moby/sys/signal"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
const defaultSignal = "SIGTERM"
@@ -61,23 +61,25 @@ func RemoveCniNetworkIfExist(ctx context.Context, container containerd.Container
return nil
}
var killCommand = cli.Command{
var killCommand = &cli.Command{
Name: "kill",
Usage: "Signal a container (default: SIGTERM)",
ArgsUsage: "[flags] CONTAINER",
Flags: []cli.Flag{
cli.StringFlag{
Name: "signal, s",
Value: "",
Usage: "Signal to send to the container",
&cli.StringFlag{
Name: "signal",
Aliases: []string{"s"},
Value: "",
Usage: "Signal to send to the container",
},
cli.StringFlag{
&cli.StringFlag{
Name: "exec-id",
Usage: "Process ID to kill",
},
cli.BoolFlag{
Name: "all, a",
Usage: "Send signal to all processes inside the container",
&cli.BoolFlag{
Name: "all",
Aliases: []string{"a"},
Usage: "Send signal to all processes inside the container",
},
},
Action: func(context *cli.Context) error {

View File

@@ -23,18 +23,19 @@ import (
tasks "github.com/containerd/containerd/v2/api/services/tasks/v1"
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var listCommand = cli.Command{
var listCommand = &cli.Command{
Name: "list",
Usage: "List tasks",
Aliases: []string{"ls"},
ArgsUsage: "[flags]",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "quiet, q",
Usage: "Print only the task id",
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "Print only the task id",
},
},
Action: func(context *cli.Context) error {

View File

@@ -28,7 +28,7 @@ import (
v2 "github.com/containerd/cgroups/v3/cgroup2/stats"
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/containerd/typeurl/v2"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
const (
@@ -37,13 +37,13 @@ const (
formatJSON = "json"
)
var metricsCommand = cli.Command{
var metricsCommand = &cli.Command{
Name: "metrics",
Usage: "Get a single data point of metrics for a task with the built-in Linux runtime",
ArgsUsage: "CONTAINER",
Aliases: []string{"metric"},
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: formatFlag,
Usage: `"table" or "json"`,
Value: formatTable,

View File

@@ -18,10 +18,10 @@ package tasks
import (
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var pauseCommand = cli.Command{
var pauseCommand = &cli.Command{
Name: "pause",
Usage: "Pause an existing container",
ArgsUsage: "CONTAINER",

View File

@@ -24,10 +24,10 @@ import (
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/containerd/typeurl/v2"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var psCommand = cli.Command{
var psCommand = &cli.Command{
Name: "ps",
Usage: "List processes for container",
ArgsUsage: "CONTAINER",

View File

@@ -18,10 +18,10 @@ package tasks
import (
"github.com/containerd/containerd/v2/cmd/ctr/commands"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var resumeCommand = cli.Command{
var resumeCommand = &cli.Command{
Name: "resume",
Usage: "Resume a paused container",
ArgsUsage: "CONTAINER",

View File

@@ -25,33 +25,34 @@ import (
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var startCommand = cli.Command{
var startCommand = &cli.Command{
Name: "start",
Usage: "Start a container that has been created",
ArgsUsage: "CONTAINER",
Flags: append(platformStartFlags, []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "null-io",
Usage: "Send all IO to /dev/null",
},
cli.StringFlag{
&cli.StringFlag{
Name: "log-uri",
Usage: "Log uri",
},
cli.StringFlag{
&cli.StringFlag{
Name: "fifo-dir",
Usage: "Directory used for storing IO FIFOs",
},
cli.StringFlag{
&cli.StringFlag{
Name: "pid-file",
Usage: "File path to write the task's pid",
},
cli.BoolFlag{
Name: "detach,d",
Usage: "Detach from the task after it has started execution",
&cli.BoolFlag{
Name: "detach",
Aliases: []string{"d"},
Usage: "Detach from the task after it has started execution",
},
}...),
Action: func(context *cli.Context) error {
@@ -137,7 +138,7 @@ var startCommand = cli.Command{
return err
}
if code != 0 {
return cli.NewExitError("", int(code))
return cli.Exit("", int(code))
}
return nil
},

View File

@@ -19,7 +19,7 @@ package tasks
import (
gocontext "context"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
type resizer interface {
@@ -27,11 +27,11 @@ type resizer interface {
}
// Command is the cli command for managing tasks
var Command = cli.Command{
var Command = &cli.Command{
Name: "tasks",
Usage: "Manage tasks",
Aliases: []string{"t", "task"},
Subcommands: []cli.Command{
Subcommands: []*cli.Command{
attachCommand,
checkpointCommand,
deleteCommand,

View File

@@ -29,12 +29,12 @@ import (
containerd "github.com/containerd/containerd/v2/client"
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/log"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"golang.org/x/sys/unix"
)
var platformStartFlags = []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "no-pivot",
Usage: "Disable use of pivot-root (linux only)",
},

View File

@@ -26,7 +26,7 @@ import (
containerd "github.com/containerd/containerd/v2/client"
"github.com/containerd/containerd/v2/pkg/cio"
"github.com/containerd/log"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)
var platformStartFlags = []cli.Flag{}