فهرست منبع

Use v2 of urfave/cli

Signed-off-by: Guillaume Lours <[email protected]>
Guillaume Lours 5 سال پیش
والد
کامیت
8db55e8c5c
7فایلهای تغییر یافته به همراه24 افزوده شده و 23 حذف شده
  1. 1 1
      cmd/context.go
  2. 1 1
      cmd/example.go
  3. 8 8
      cmd/main.go
  4. 5 4
      context/flags.go
  5. 6 6
      example/backend/main.go
  6. 1 1
      go.mod
  7. 2 2
      go.sum

+ 1 - 1
cmd/context.go

@@ -29,7 +29,7 @@ package main
 
 import (
 	"github.com/pkg/errors"
-	"github.com/urfave/cli"
+	"github.com/urfave/cli/v2"
 )
 
 var contextCommand = cli.Command{

+ 1 - 1
cmd/example.go

@@ -37,7 +37,7 @@ import (
 	"github.com/docker/api/client"
 	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/pkg/errors"
-	"github.com/urfave/cli"
+	"github.com/urfave/cli/v2"
 )
 
 var exampleCommand = cli.Command{

+ 8 - 8
cmd/main.go

@@ -38,7 +38,7 @@ import (
 
 	"github.com/docker/api/context"
 	"github.com/sirupsen/logrus"
-	"github.com/urfave/cli"
+	"github.com/urfave/cli/v2"
 )
 
 func init() {
@@ -61,12 +61,12 @@ func main() {
 	app.UseShortOptionHandling = true
 	app.EnableBashCompletion = true
 	app.Flags = []cli.Flag{
-		cli.BoolFlag{
+		&cli.BoolFlag{
 			Name:  "debug",
 			Usage: "enable debug output in the logs",
 		},
-		context.ConfigFlag,
-		context.ContextFlag,
+		&context.ConfigFlag,
+		&context.ContextFlag,
 	}
 
 	// Make a copy of the default HelpPrinter function
@@ -87,7 +87,7 @@ func main() {
 	}
 
 	app.Before = func(clix *cli.Context) error {
-		if clix.GlobalBool("debug") {
+		if clix.Bool("debug") {
 			logrus.SetLevel(logrus.DebugLevel)
 		}
 		ctx, err := context.GetContext()
@@ -100,9 +100,9 @@ func main() {
 		// TODO select backend based on context.Metadata.Type
 		return nil
 	}
-	app.Commands = []cli.Command{
-		contextCommand,
-		exampleCommand,
+	app.Commands = []*cli.Command{
+		&contextCommand,
+		&exampleCommand,
 	}
 
 	sort.Sort(cli.FlagsByName(app.Flags))

+ 5 - 4
context/flags.go

@@ -4,7 +4,7 @@ import (
 	"path/filepath"
 
 	"github.com/mitchellh/go-homedir"
-	"github.com/urfave/cli"
+	"github.com/urfave/cli/v2"
 )
 
 const (
@@ -19,15 +19,16 @@ var (
 	ConfigFlag  = cli.StringFlag{
 		Name:        "config",
 		Usage:       "Location of client config files `DIRECTORY`",
-		EnvVar:      "DOCKER_CONFIG",
+		EnvVars:      []string{"DOCKER_CONFIG"},
 		Value:       filepath.Join(home(), configFileDir),
 		Destination: &ConfigDir,
 	}
 
 	ContextFlag = cli.StringFlag{
-		Name:        "context, c",
+		Name:        "context",
+		Aliases: 	 []string{"c"},
 		Usage:       "Name of the context `CONTEXT` to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with \"docker context use\")",
-		EnvVar:      "DOCKER_CONTEXT",
+		EnvVars:      []string{"DOCKER_CONTEXT"},
 		Destination: &ContextName,
 	}
 )

+ 6 - 6
example/backend/main.go

@@ -39,7 +39,7 @@ import (
 	"github.com/golang/protobuf/ptypes/empty"
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
-	"github.com/urfave/cli"
+	"github.com/urfave/cli/v2"
 )
 
 func main() {
@@ -50,17 +50,17 @@ func main() {
 	app.UseShortOptionHandling = true
 	app.EnableBashCompletion = true
 	app.Flags = []cli.Flag{
-		cli.BoolFlag{
+		&cli.BoolFlag{
 			Name:  "debug",
 			Usage: "enable debug output in the logs",
 		},
-		cli.StringFlag{
+		&cli.StringFlag{
 			Name:  "address,a",
 			Usage: "address of the server",
 		},
 	}
 	app.Before = func(clix *cli.Context) error {
-		if clix.GlobalBool("debug") {
+		if clix.Bool("debug") {
 			logrus.SetLevel(logrus.DebugLevel)
 		}
 		return nil
@@ -73,7 +73,7 @@ func main() {
 		s := server.New()
 
 		// listen on a socket to accept connects
-		l, err := net.Listen("unix", clix.GlobalString("address"))
+		l, err := net.Listen("unix", clix.String("address"))
 		if err != nil {
 			return errors.Wrap(err, "listen unix socket")
 		}
@@ -93,7 +93,7 @@ func main() {
 			s.Stop()
 		}()
 
-		logrus.WithField("address", clix.GlobalString("address")).Info("serving daemon API")
+		logrus.WithField("address", clix.String("address")).Info("serving daemon API")
 		// start the GRPC server to serve on the listener
 		return s.Serve(l)
 	}

+ 1 - 1
go.mod

@@ -10,7 +10,7 @@ require (
 	github.com/pkg/errors v0.9.1
 	github.com/prometheus/client_golang v1.5.1 // indirect
 	github.com/sirupsen/logrus v1.5.0
-	github.com/urfave/cli v1.22.4
+	github.com/urfave/cli/v2 v2.2.0
 	google.golang.org/grpc v1.28.1
 	google.golang.org/protobuf v1.21.0
 )

+ 2 - 2
go.sum

@@ -105,8 +105,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
-github.com/urfave/cli v1.22.4 h1:u7tSpNPPswAFymm8IehJhy4uJMlUuU/GmqSkvJ1InXA=
-github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
+github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
+github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=