From f6adad559ab66190decace5c997d88094d17cfc6 Mon Sep 17 00:00:00 2001 From: Jeffsky Date: Tue, 4 Feb 2020 20:21:51 +0800 Subject: [PATCH] upgrade 'github.com/urfave/cli' to v2. --- cmd/rsocket-cli/rsocket-cli.go | 71 +++++++++++++++++++--------------- cmd/rsocket-cli/runner.go | 19 +++++---- go.mod | 2 +- go.sum | 8 +--- 4 files changed, 55 insertions(+), 45 deletions(-) diff --git a/cmd/rsocket-cli/rsocket-cli.go b/cmd/rsocket-cli/rsocket-cli.go index da67c4f..862044c 100644 --- a/cmd/rsocket-cli/rsocket-cli.go +++ b/cmd/rsocket-cli/rsocket-cli.go @@ -9,7 +9,7 @@ import ( "github.com/rsocket/rsocket-go/extension" "github.com/rsocket/rsocket-go/logger" "github.com/rsocket/rsocket-go/rx" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func init() { @@ -27,10 +27,11 @@ func init() { func main() { conf := &Runner{} app := cli.NewApp() + app.UseShortOptionHandling = true app.UsageText = "rsocket-cli [global options] [URI]" app.Name = "rsocket-cli" app.Usage = "CLI for RSocket." - app.Version = "v0.5.5" + app.Version = "v0.5.6" app.Flags = newFlags(conf) app.ArgsUsage = "[URI]" app.Action = func(c *cli.Context) (err error) { @@ -50,104 +51,112 @@ func main() { func newFlags(args *Runner) []cli.Flag { return []cli.Flag{ &cli.StringSliceFlag{ - Name: "header,H", - Usage: "Custom header to pass to server", - Value: (*cli.StringSlice)(&args.Headers), + Name: "header", + Usage: "Custom header to pass to server", + Value: &args.Headers, + Aliases: []string{"H"}, }, &cli.StringSliceFlag{ - Name: "transport-header,T", - Usage: "Custom header to pass to the transport", - Value: (*cli.StringSlice)(&args.TransportHeaders), + Name: "transport-header", + Usage: "Custom header to pass to the transport", + Value: &args.TransportHeaders, + Aliases: []string{"T"}, }, &cli.BoolFlag{ Name: "stream", Usage: "Request Stream", - Destination: &(args.Stream), + Destination: &args.Stream, }, &cli.BoolFlag{ Name: "request", Usage: "Request Response", - Destination: &(args.Request), + Destination: &args.Request, }, &cli.BoolFlag{ Name: "fnf", Usage: "Fire And Forget", - Destination: &(args.FNF), + Destination: &args.FNF, }, &cli.BoolFlag{ Name: "channel", Usage: "Channel", - Destination: &(args.Channel), + Destination: &args.Channel, }, &cli.BoolFlag{ Name: "metadataPush", Usage: "Metadata Push", - Destination: &(args.MetadataPush), + Destination: &args.MetadataPush, }, &cli.BoolFlag{ - Name: "server,s", + Name: "server", Usage: "Start server instead of client", - Destination: &(args.ServerMode), + Destination: &args.ServerMode, + Aliases: []string{"s"}, }, &cli.StringFlag{ - Name: "input,i", + Name: "input", Usage: "String input, '-' (STDIN) or @path/to/file", - Destination: &(args.Input), + Destination: &args.Input, + Aliases: []string{"i"}, }, &cli.StringFlag{ - Name: "metadata, m", + Name: "metadata", Usage: "Metadata input string input or @path/to/file", - Destination: &(args.Metadata), + Destination: &args.Metadata, + Aliases: []string{"m"}, }, &cli.StringFlag{ Name: "metadataFormat", Usage: "Metadata Format", Value: extension.ApplicationJSON.String(), - Destination: &(args.MetadataFormat), + Destination: &args.MetadataFormat, }, &cli.StringFlag{ Name: "dataFormat", Usage: "Data Format", Value: "application/binary", - Destination: &(args.DataFormat), + Destination: &args.DataFormat, }, &cli.StringFlag{ Name: "setup", Usage: "String input or @path/to/file for setup metadata", - Destination: &(args.Setup), + Destination: &args.Setup, }, &cli.BoolFlag{ - Name: "debug,d", + Name: "debug", Usage: "Debug Output", - Destination: &(args.Debug), + Destination: &args.Debug, + Aliases: []string{"d"}, }, &cli.IntFlag{ Name: "ops", Usage: "Operation Count", Value: 1, - Destination: &(args.Ops), + Destination: &args.Ops, }, &cli.DurationFlag{ Name: "timeout", Usage: "Timeout in seconds", - Destination: &(args.Timeout), + Destination: &args.Timeout, }, &cli.DurationFlag{ - Name: "keepalive,k", + Name: "keepalive", Usage: "Keepalive period", Value: 20 * time.Second, - Destination: &(args.Keepalive), + Destination: &args.Keepalive, + Aliases: []string{"k"}, }, &cli.IntFlag{ - Name: "requestn, r", + Name: "requestn", Usage: "Request N credits", Value: rx.RequestMax, - Destination: &(args.N), + Destination: &args.N, + Aliases: []string{"r"}, }, &cli.BoolFlag{ Name: "resume", Usage: "resume enabled", - Destination: &(args.Resume), + Destination: &args.Resume, }, } diff --git a/cmd/rsocket-cli/runner.go b/cmd/rsocket-cli/runner.go index be45735..82aa7d1 100644 --- a/cmd/rsocket-cli/runner.go +++ b/cmd/rsocket-cli/runner.go @@ -17,13 +17,14 @@ import ( "github.com/rsocket/rsocket-go/rx" "github.com/rsocket/rsocket-go/rx/flux" "github.com/rsocket/rsocket-go/rx/mono" + "github.com/urfave/cli/v2" ) var errConflictHeadersAndMetadata = errors.New("can't specify headers and metadata") type Runner struct { - Headers []string - TransportHeaders []string + Headers cli.StringSlice + TransportHeaders cli.StringSlice Stream bool Request bool FNF bool @@ -49,12 +50,15 @@ func (p *Runner) preflight() (err error) { if p.Debug { logger.SetLevel(logger.LevelDebug) } - if len(p.Headers) > 0 && len(p.Metadata) > 0 { + + headers := p.Headers.Value() + + if len(headers) > 0 && len(p.Metadata) > 0 { return errConflictHeadersAndMetadata } - if len(p.Headers) > 0 { + if len(headers) > 0 { headers := make(map[string]string) - for _, it := range p.Headers { + for _, it := range headers { idx := strings.Index(it, ":") if idx < 0 { return fmt.Errorf("invalid header: %s", it) @@ -67,9 +71,10 @@ func (p *Runner) preflight() (err error) { p.Metadata = string(bs) } - if len(p.TransportHeaders) > 0 { + tpHeaders := p.TransportHeaders.Value() + if len(tpHeaders) > 0 { headers := make(map[string][]string) - for _, it := range p.TransportHeaders { + for _, it := range tpHeaders { idx := strings.Index(it, ":") if idx < 0 { return fmt.Errorf("invalid transport header: %s", it) diff --git a/go.mod b/go.mod index e7d2b32..320270d 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,6 @@ require ( github.com/jjeffcaii/reactor-go v0.1.1 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.4.0 - github.com/urfave/cli v1.22.2 + github.com/urfave/cli/v2 v2.1.1 go.uber.org/atomic v1.5.1 ) diff --git a/go.sum b/go.sum index 7cb27e6..6774793 100644 --- a/go.sum +++ b/go.sum @@ -2,7 +2,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -14,7 +13,6 @@ github.com/panjf2000/ants v1.2.0 h1:pMQ1/XpSgnWx3ro4y1xr/uA3jXUsTuAaU3Dm0JjwggE= github.com/panjf2000/ants v1.2.0/go.mod h1:AaACblRPzq35m1g3enqYcxspbbiOJJYaxU2wMpm1cXY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -22,10 +20,9 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= +github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= go.uber.org/atomic v1.5.1 h1:rsqfU5vBkVknbhUGbAUwQKR2H4ItV8tjJ+6kJX4cxHM= go.uber.org/atomic v1.5.1/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -39,5 +36,4 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=