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:
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/containerd/console"
|
||||
gocni "github.com/containerd/go-cni"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
containerd "github.com/containerd/containerd/v2/client"
|
||||
"github.com/containerd/containerd/v2/cmd/ctr/commands"
|
||||
@@ -89,41 +89,41 @@ func parseMountFlag(m string) (specs.Mount, error) {
|
||||
}
|
||||
|
||||
// Command runs a container
|
||||
var Command = cli.Command{
|
||||
Name: "run",
|
||||
Usage: "Run a container",
|
||||
ArgsUsage: "[flags] Image|RootFS ID [COMMAND] [ARG...]",
|
||||
SkipArgReorder: true,
|
||||
var Command = &cli.Command{
|
||||
Name: "run",
|
||||
Usage: "Run a container",
|
||||
ArgsUsage: "[flags] Image|RootFS ID [COMMAND] [ARG...]",
|
||||
Flags: append([]cli.Flag{
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "rm",
|
||||
Usage: "Remove the container after running, cannot be used with --detach",
|
||||
},
|
||||
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.BoolFlag{
|
||||
Name: "detach,d",
|
||||
Usage: "Detach from the task after it has started execution, cannot be used with --rm",
|
||||
&cli.BoolFlag{
|
||||
Name: "detach",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "Detach from the task after it has started execution, cannot be used with --rm",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "fifo-dir",
|
||||
Usage: "Directory used for storing IO FIFOs",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "cgroup",
|
||||
Usage: "Cgroup path (To disable use of cgroup, set to \"\" explicitly)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "platform",
|
||||
Usage: "Run image for specific platform",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "cni",
|
||||
Usage: "Enable cni networking for the container",
|
||||
},
|
||||
@@ -259,7 +259,7 @@ var Command = cli.Command{
|
||||
return err
|
||||
}
|
||||
if code != 0 {
|
||||
return cli.NewExitError("", int(code))
|
||||
return cli.Exit("", int(code))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -39,43 +39,43 @@ import (
|
||||
"github.com/containerd/platforms"
|
||||
"github.com/intel/goresctrl/pkg/blockio"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"tags.cncf.io/container-device-interface/pkg/cdi"
|
||||
"tags.cncf.io/container-device-interface/pkg/parser"
|
||||
)
|
||||
|
||||
var platformRunFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "uidmap",
|
||||
Usage: "Run inside a user namespace with the specified UID mapping range; specified with the format `container-uid:host-uid:length`",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "gidmap",
|
||||
Usage: "Run inside a user namespace with the specified GID mapping range; specified with the format `container-gid:host-gid:length`",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "remap-labels",
|
||||
Usage: "Provide the user namespace ID remapping to the snapshotter via label options; requires snapshotter support",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "privileged-without-host-devices",
|
||||
Usage: "Don't pass all host devices to privileged container",
|
||||
},
|
||||
cli.Float64Flag{
|
||||
&cli.Float64Flag{
|
||||
Name: "cpus",
|
||||
Usage: "Set the CFS cpu quota",
|
||||
Value: 0.0,
|
||||
},
|
||||
cli.IntFlag{
|
||||
&cli.IntFlag{
|
||||
Name: "cpu-shares",
|
||||
Usage: "Set the cpu shares",
|
||||
Value: 1024,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "cpuset-cpus",
|
||||
Usage: "Set the CPUs the container will run in (e.g., 1-2,4)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "cpuset-mems",
|
||||
Usage: "Set the memory nodes the container will run in (e.g., 1-2,4)",
|
||||
},
|
||||
@@ -110,7 +110,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
// for container's id is Args[1]
|
||||
args = context.Args()[2:]
|
||||
args = context.Args().Slice()[2:]
|
||||
)
|
||||
opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices)
|
||||
if ef := context.String("env-file"); ef != "" {
|
||||
|
||||
@@ -30,11 +30,11 @@ import (
|
||||
"github.com/containerd/containerd/v2/pkg/oci"
|
||||
"github.com/containerd/log"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var platformRunFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "isolated",
|
||||
Usage: "Run the container with vm isolation",
|
||||
},
|
||||
@@ -62,7 +62,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
} else {
|
||||
var (
|
||||
ref = context.Args().First()
|
||||
args = context.Args()[2:]
|
||||
args = context.Args().Slice()[2:]
|
||||
)
|
||||
|
||||
id = context.Args().Get(1)
|
||||
@@ -176,7 +176,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
var runtimeOpts interface{}
|
||||
if runtime == "io.containerd.runhcs.v1" {
|
||||
runtimeOpts = &options.Options{
|
||||
Debug: context.GlobalBool("debug"),
|
||||
Debug: context.Bool("debug"),
|
||||
}
|
||||
}
|
||||
cOpts = append(cOpts, containerd.WithRuntime(runtime, runtimeOpts))
|
||||
|
||||
Reference in New Issue
Block a user