Merge pull request #9809 from dereknola/urfave_v2
Migrate Urfave CLI from v1 to v2
This commit is contained in:
@@ -30,7 +30,7 @@ import (
|
||||
"github.com/containerd/plugin/registry"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func outputConfig(ctx gocontext.Context, config *srvconfig.Config) error {
|
||||
@@ -79,10 +79,10 @@ func defaultConfig() *srvconfig.Config {
|
||||
return platformAgnosticDefaultConfig()
|
||||
}
|
||||
|
||||
var configCommand = cli.Command{
|
||||
var configCommand = &cli.Command{
|
||||
Name: "config",
|
||||
Usage: "Information on the containerd config",
|
||||
Subcommands: []cli.Command{
|
||||
Subcommands: []*cli.Command{
|
||||
{
|
||||
Name: "default",
|
||||
Usage: "See the output of the default config",
|
||||
@@ -96,7 +96,7 @@ var configCommand = cli.Command{
|
||||
Action: func(context *cli.Context) error {
|
||||
config := defaultConfig()
|
||||
ctx := gocontext.Background()
|
||||
if err := srvconfig.LoadConfig(ctx, context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) {
|
||||
if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ var configCommand = cli.Command{
|
||||
Action: func(context *cli.Context) error {
|
||||
config := defaultConfig()
|
||||
ctx := gocontext.Background()
|
||||
if err := srvconfig.LoadConfig(ctx, context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) {
|
||||
if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
"github.com/containerd/containerd/v2/version"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/containerd/log"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
)
|
||||
|
||||
@@ -57,13 +57,15 @@ func init() {
|
||||
cli.VersionPrinter = func(c *cli.Context) {
|
||||
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)
|
||||
}
|
||||
cli.VersionFlag = cli.BoolFlag{
|
||||
Name: "version, v",
|
||||
Usage: "Print the version",
|
||||
cli.VersionFlag = &cli.BoolFlag{
|
||||
Name: "version",
|
||||
Aliases: []string{"v"},
|
||||
Usage: "Print the version",
|
||||
}
|
||||
cli.HelpFlag = cli.BoolFlag{
|
||||
Name: "help, h",
|
||||
Usage: "Show help",
|
||||
cli.HelpFlag = &cli.BoolFlag{
|
||||
Name: "help",
|
||||
Aliases: []string{"h"},
|
||||
Usage: "Show help",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,30 +87,33 @@ at the default file location. The *containerd config* command can be used to
|
||||
generate the default configuration for containerd. The output of that command
|
||||
can be used and modified as necessary as a custom configuration.`
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "config,c",
|
||||
Usage: "Path to the configuration file",
|
||||
Value: filepath.Join(defaults.DefaultConfigDir, "config.toml"),
|
||||
&cli.StringFlag{
|
||||
Name: "config",
|
||||
Aliases: []string{"c"},
|
||||
Usage: "Path to the configuration file",
|
||||
Value: filepath.Join(defaults.DefaultConfigDir, "config.toml"),
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log-level,l",
|
||||
Usage: "Set the logging level [trace, debug, info, warn, error, fatal, panic]",
|
||||
&cli.StringFlag{
|
||||
Name: "log-level",
|
||||
Aliases: []string{"l"},
|
||||
Usage: "Set the logging level [trace, debug, info, warn, error, fatal, panic]",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "address,a",
|
||||
Usage: "Address for containerd's GRPC server",
|
||||
&cli.StringFlag{
|
||||
Name: "address",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "Address for containerd's GRPC server",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "root",
|
||||
Usage: "containerd root directory",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
Usage: "containerd state directory",
|
||||
},
|
||||
}
|
||||
app.Flags = append(app.Flags, serviceFlags()...)
|
||||
app.Commands = []cli.Command{
|
||||
app.Commands = []*cli.Command{
|
||||
configCommand,
|
||||
publishCommand,
|
||||
ociHook,
|
||||
@@ -126,9 +131,9 @@ can be used and modified as necessary as a custom configuration.`
|
||||
|
||||
// Only try to load the config if it either exists, or the user explicitly
|
||||
// told us to load this path.
|
||||
configPath := context.GlobalString("config")
|
||||
configPath := context.String("config")
|
||||
_, err := os.Stat(configPath)
|
||||
if !os.IsNotExist(err) || context.GlobalIsSet("config") {
|
||||
if !os.IsNotExist(err) || context.IsSet("config") {
|
||||
if err := srvconfig.LoadConfig(ctx, configPath, config); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -336,7 +341,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
|
||||
d: &config.GRPC.Address,
|
||||
},
|
||||
} {
|
||||
if s := context.GlobalString(v.name); s != "" {
|
||||
if s := context.String(v.name); s != "" {
|
||||
*v.d = s
|
||||
if v.name == "root" || v.name == "state" {
|
||||
absPath, err := filepath.Abs(s)
|
||||
@@ -354,7 +359,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
|
||||
}
|
||||
|
||||
func setLogLevel(context *cli.Context, config *srvconfig.Config) error {
|
||||
l := context.GlobalString("log-level")
|
||||
l := context.String("log-level")
|
||||
if l == "" {
|
||||
l = config.Debug.Level
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/v2/pkg/oci"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var ociHook = cli.Command{
|
||||
var ociHook = &cli.Command{
|
||||
Name: "oci-hook",
|
||||
Usage: "Provides a base for OCI runtime hooks to allow arguments to be injected.",
|
||||
Action: func(context *cli.Context) error {
|
||||
@@ -45,7 +45,7 @@ var ociHook = cli.Command{
|
||||
}
|
||||
var (
|
||||
ctx = newTemplateContext(state, spec)
|
||||
args = []string(context.Args())
|
||||
args = context.Args().Slice()
|
||||
env = os.Environ()
|
||||
)
|
||||
if err := newList(&args).render(ctx); err != nil {
|
||||
|
||||
@@ -30,21 +30,21 @@ import (
|
||||
"github.com/containerd/containerd/v2/protobuf/proto"
|
||||
"github.com/containerd/containerd/v2/protobuf/types"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
var publishCommand = cli.Command{
|
||||
var publishCommand = &cli.Command{
|
||||
Name: "publish",
|
||||
Usage: "Binary to publish events to containerd",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "namespace",
|
||||
Usage: "Namespace to publish to",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "topic",
|
||||
Usage: "Topic of the event",
|
||||
},
|
||||
@@ -59,7 +59,7 @@ var publishCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := connectEvents(context.GlobalString("address"))
|
||||
client, err := connectEvents(context.String("address"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package command
|
||||
|
||||
import (
|
||||
"github.com/containerd/containerd/v2/cmd/containerd/server"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// serviceFlags returns an array of flags for configuring containerd to run
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"github.com/containerd/containerd/v2/cmd/containerd/server"
|
||||
"github.com/containerd/errdefs"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/sys/windows"
|
||||
"golang.org/x/sys/windows/svc"
|
||||
"golang.org/x/sys/windows/svc/debug"
|
||||
@@ -53,25 +53,25 @@ const defaultServiceName = "containerd"
|
||||
// as a Windows service under control of SCM.
|
||||
func serviceFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "service-name",
|
||||
Usage: "Set the Windows service name",
|
||||
Value: defaultServiceName,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "register-service",
|
||||
Usage: "Register the service and exit",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "unregister-service",
|
||||
Usage: "Unregister the service and exit",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "run-service",
|
||||
Usage: "",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "log-file",
|
||||
Usage: "Path to the containerd log file",
|
||||
},
|
||||
@@ -80,7 +80,7 @@ func serviceFlags() []cli.Flag {
|
||||
|
||||
// applyPlatformFlags applies platform-specific flags.
|
||||
func applyPlatformFlags(context *cli.Context) {
|
||||
serviceNameFlag = context.GlobalString("service-name")
|
||||
serviceNameFlag = context.String("service-name")
|
||||
if serviceNameFlag == "" {
|
||||
serviceNameFlag = defaultServiceName
|
||||
}
|
||||
@@ -101,9 +101,9 @@ func applyPlatformFlags(context *cli.Context) {
|
||||
d: &runServiceFlag,
|
||||
},
|
||||
} {
|
||||
*v.d = context.GlobalBool(v.name)
|
||||
*v.d = context.Bool(v.name)
|
||||
}
|
||||
logFileFlag = context.GlobalString("log-file")
|
||||
logFileFlag = context.String("log-file")
|
||||
}
|
||||
|
||||
type handler struct {
|
||||
|
||||
Reference in New Issue
Block a user