Skip to content

Commit

Permalink
upgrade 'github.com/urfave/cli' to v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii committed Feb 4, 2020
1 parent cb1d2b6 commit f6adad5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
71 changes: 40 additions & 31 deletions cmd/rsocket-cli/rsocket-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand All @@ -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,
},
}

Expand Down
19 changes: 12 additions & 7 deletions cmd/rsocket-cli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -14,18 +13,16 @@ 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=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
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=
Expand All @@ -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=

0 comments on commit f6adad5

Please sign in to comment.