|
|
@ -304,13 +304,14 @@ func TestParseMultiString(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
StringFlag{Name: "serve, s"},
|
|
|
|
StringFlag{Name: "serve, s"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.String("serve") != "10" {
|
|
|
|
if ctx.String("serve") != "10" {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.String("s") != "10" {
|
|
|
|
if ctx.String("s") != "10" {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run", "-s", "10"})
|
|
|
|
}).Run([]string{"run", "-s", "10"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -324,10 +325,11 @@ func TestParseDestinationString(t *testing.T) {
|
|
|
|
Destination: &dest,
|
|
|
|
Destination: &dest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if dest != "10" {
|
|
|
|
if dest != "10" {
|
|
|
|
t.Errorf("expected destination String 10")
|
|
|
|
t.Errorf("expected destination String 10")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "--dest", "10"})
|
|
|
|
a.Run([]string{"run", "--dest", "10"})
|
|
|
@ -340,13 +342,14 @@ func TestParseMultiStringFromEnv(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
StringFlag{Name: "count, c", EnvVar: "APP_COUNT"},
|
|
|
|
StringFlag{Name: "count, c", EnvVar: "APP_COUNT"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.String("count") != "20" {
|
|
|
|
if ctx.String("count") != "20" {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.String("c") != "20" {
|
|
|
|
if ctx.String("c") != "20" {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -358,13 +361,14 @@ func TestParseMultiStringFromEnvCascade(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
StringFlag{Name: "count, c", EnvVar: "COMPAT_COUNT,APP_COUNT"},
|
|
|
|
StringFlag{Name: "count, c", EnvVar: "COMPAT_COUNT,APP_COUNT"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.String("count") != "20" {
|
|
|
|
if ctx.String("count") != "20" {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.String("c") != "20" {
|
|
|
|
if ctx.String("c") != "20" {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -374,7 +378,7 @@ func TestParseMultiStringSlice(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
StringSliceFlag{Name: "serve, s", Value: NewStringSlice()},
|
|
|
|
StringSliceFlag{Name: "serve, s", Value: NewStringSlice()},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
expected := []string{"10", "20"}
|
|
|
|
expected := []string{"10", "20"}
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("serve"), expected) {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("serve"), expected) {
|
|
|
|
t.Errorf("main name not set: %v != %v", expected, ctx.StringSlice("serve"))
|
|
|
|
t.Errorf("main name not set: %v != %v", expected, ctx.StringSlice("serve"))
|
|
|
@ -382,6 +386,7 @@ func TestParseMultiStringSlice(t *testing.T) {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("s"), expected) {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("s"), expected) {
|
|
|
|
t.Errorf("short name not set: %v != %v", expected, ctx.StringSlice("s"))
|
|
|
|
t.Errorf("short name not set: %v != %v", expected, ctx.StringSlice("s"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run", "-s", "10", "-s", "20"})
|
|
|
|
}).Run([]string{"run", "-s", "10", "-s", "20"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -446,13 +451,14 @@ func TestParseMultiStringSliceFromEnvWithDefaults(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
StringSliceFlag{Name: "intervals, i", Value: NewStringSlice("1", "2", "5"), EnvVar: "APP_INTERVALS"},
|
|
|
|
StringSliceFlag{Name: "intervals, i", Value: NewStringSlice("1", "2", "5"), EnvVar: "APP_INTERVALS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("intervals"), []string{"20", "30", "40"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("intervals"), []string{"20", "30", "40"}) {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("i"), []string{"20", "30", "40"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("i"), []string{"20", "30", "40"}) {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -484,13 +490,14 @@ func TestParseMultiStringSliceFromEnvCascadeWithDefaults(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
StringSliceFlag{Name: "intervals, i", Value: NewStringSlice("1", "2", "5"), EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
|
|
|
StringSliceFlag{Name: "intervals, i", Value: NewStringSlice("1", "2", "5"), EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("intervals"), []string{"20", "30", "40"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("intervals"), []string{"20", "30", "40"}) {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("i"), []string{"20", "30", "40"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("i"), []string{"20", "30", "40"}) {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -500,13 +507,14 @@ func TestParseMultiInt(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
IntFlag{Name: "serve, s"},
|
|
|
|
IntFlag{Name: "serve, s"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Int("serve") != 10 {
|
|
|
|
if ctx.Int("serve") != 10 {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Int("s") != 10 {
|
|
|
|
if ctx.Int("s") != 10 {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "-s", "10"})
|
|
|
|
a.Run([]string{"run", "-s", "10"})
|
|
|
@ -521,10 +529,11 @@ func TestParseDestinationInt(t *testing.T) {
|
|
|
|
Destination: &dest,
|
|
|
|
Destination: &dest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if dest != 10 {
|
|
|
|
if dest != 10 {
|
|
|
|
t.Errorf("expected destination Int 10")
|
|
|
|
t.Errorf("expected destination Int 10")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "--dest", "10"})
|
|
|
|
a.Run([]string{"run", "--dest", "10"})
|
|
|
@ -537,13 +546,14 @@ func TestParseMultiIntFromEnv(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
IntFlag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
|
|
|
IntFlag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Int("timeout") != 10 {
|
|
|
|
if ctx.Int("timeout") != 10 {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Int("t") != 10 {
|
|
|
|
if ctx.Int("t") != 10 {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -556,13 +566,14 @@ func TestParseMultiIntFromEnvCascade(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
IntFlag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
|
|
|
IntFlag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Int("timeout") != 10 {
|
|
|
|
if ctx.Int("timeout") != 10 {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Int("t") != 10 {
|
|
|
|
if ctx.Int("t") != 10 {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -573,13 +584,14 @@ func TestParseMultiIntSlice(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
IntSliceFlag{Name: "serve, s", Value: NewIntSlice()},
|
|
|
|
IntSliceFlag{Name: "serve, s", Value: NewIntSlice()},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("serve"), []int{10, 20}) {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("serve"), []int{10, 20}) {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("s"), []int{10, 20}) {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("s"), []int{10, 20}) {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run", "-s", "10", "-s", "20"})
|
|
|
|
}).Run([]string{"run", "-s", "10", "-s", "20"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -643,13 +655,14 @@ func TestParseMultiIntSliceFromEnvWithDefaults(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
IntSliceFlag{Name: "intervals, i", Value: NewIntSlice(1, 2, 5), EnvVar: "APP_INTERVALS"},
|
|
|
|
IntSliceFlag{Name: "intervals, i", Value: NewIntSlice(1, 2, 5), EnvVar: "APP_INTERVALS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("intervals"), []int{20, 30, 40}) {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("intervals"), []int{20, 30, 40}) {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("i"), []int{20, 30, 40}) {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("i"), []int{20, 30, 40}) {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -662,13 +675,14 @@ func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
IntSliceFlag{Name: "intervals, i", Value: NewIntSlice(), EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
|
|
|
IntSliceFlag{Name: "intervals, i", Value: NewIntSlice(), EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("intervals"), []int{20, 30, 40}) {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("intervals"), []int{20, 30, 40}) {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("i"), []int{20, 30, 40}) {
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("i"), []int{20, 30, 40}) {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -678,13 +692,14 @@ func TestParseMultiFloat64(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
Float64Flag{Name: "serve, s"},
|
|
|
|
Float64Flag{Name: "serve, s"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Float64("serve") != 10.2 {
|
|
|
|
if ctx.Float64("serve") != 10.2 {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Float64("s") != 10.2 {
|
|
|
|
if ctx.Float64("s") != 10.2 {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "-s", "10.2"})
|
|
|
|
a.Run([]string{"run", "-s", "10.2"})
|
|
|
@ -699,10 +714,11 @@ func TestParseDestinationFloat64(t *testing.T) {
|
|
|
|
Destination: &dest,
|
|
|
|
Destination: &dest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if dest != 10.2 {
|
|
|
|
if dest != 10.2 {
|
|
|
|
t.Errorf("expected destination Float64 10.2")
|
|
|
|
t.Errorf("expected destination Float64 10.2")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "--dest", "10.2"})
|
|
|
|
a.Run([]string{"run", "--dest", "10.2"})
|
|
|
@ -715,13 +731,14 @@ func TestParseMultiFloat64FromEnv(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
|
|
|
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Float64("timeout") != 15.5 {
|
|
|
|
if ctx.Float64("timeout") != 15.5 {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Float64("t") != 15.5 {
|
|
|
|
if ctx.Float64("t") != 15.5 {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -734,13 +751,14 @@ func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
|
|
|
Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Float64("timeout") != 15.5 {
|
|
|
|
if ctx.Float64("timeout") != 15.5 {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Float64("t") != 15.5 {
|
|
|
|
if ctx.Float64("t") != 15.5 {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -751,13 +769,14 @@ func TestParseMultiBool(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
BoolFlag{Name: "serve, s"},
|
|
|
|
BoolFlag{Name: "serve, s"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Bool("serve") != true {
|
|
|
|
if ctx.Bool("serve") != true {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Bool("s") != true {
|
|
|
|
if ctx.Bool("s") != true {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "--serve"})
|
|
|
|
a.Run([]string{"run", "--serve"})
|
|
|
@ -772,10 +791,11 @@ func TestParseDestinationBool(t *testing.T) {
|
|
|
|
Destination: &dest,
|
|
|
|
Destination: &dest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if dest != true {
|
|
|
|
if dest != true {
|
|
|
|
t.Errorf("expected destination Bool true")
|
|
|
|
t.Errorf("expected destination Bool true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "--dest"})
|
|
|
|
a.Run([]string{"run", "--dest"})
|
|
|
@ -788,13 +808,14 @@ func TestParseMultiBoolFromEnv(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
BoolFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
|
|
|
BoolFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Bool("debug") != true {
|
|
|
|
if ctx.Bool("debug") != true {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Bool("d") != true {
|
|
|
|
if ctx.Bool("d") != true {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -807,13 +828,14 @@ func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
BoolFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
|
|
|
BoolFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.Bool("debug") != true {
|
|
|
|
if ctx.Bool("debug") != true {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.Bool("d") != true {
|
|
|
|
if ctx.Bool("d") != true {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -824,13 +846,14 @@ func TestParseMultiBoolT(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
BoolTFlag{Name: "serve, s"},
|
|
|
|
BoolTFlag{Name: "serve, s"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.BoolT("serve") != true {
|
|
|
|
if ctx.BoolT("serve") != true {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.BoolT("s") != true {
|
|
|
|
if ctx.BoolT("s") != true {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "--serve"})
|
|
|
|
a.Run([]string{"run", "--serve"})
|
|
|
@ -845,10 +868,11 @@ func TestParseDestinationBoolT(t *testing.T) {
|
|
|
|
Destination: &dest,
|
|
|
|
Destination: &dest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if dest != true {
|
|
|
|
if dest != true {
|
|
|
|
t.Errorf("expected destination BoolT true")
|
|
|
|
t.Errorf("expected destination BoolT true")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "--dest"})
|
|
|
|
a.Run([]string{"run", "--dest"})
|
|
|
@ -861,13 +885,14 @@ func TestParseMultiBoolTFromEnv(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
BoolTFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
|
|
|
BoolTFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.BoolT("debug") != false {
|
|
|
|
if ctx.BoolT("debug") != false {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.BoolT("d") != false {
|
|
|
|
if ctx.BoolT("d") != false {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -880,13 +905,14 @@ func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
|
|
|
BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if ctx.BoolT("debug") != false {
|
|
|
|
if ctx.BoolT("debug") != false {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ctx.BoolT("d") != false {
|
|
|
|
if ctx.BoolT("d") != false {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -915,13 +941,14 @@ func TestParseGeneric(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
GenericFlag{Name: "serve, s", Value: &Parser{}},
|
|
|
|
GenericFlag{Name: "serve, s", Value: &Parser{}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"10", "20"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"10", "20"}) {
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"10", "20"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"10", "20"}) {
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run", "-s", "10,20"})
|
|
|
|
a.Run([]string{"run", "-s", "10,20"})
|
|
|
@ -934,13 +961,14 @@ func TestParseGenericFromEnv(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
GenericFlag{Name: "serve, s", Value: &Parser{}, EnvVar: "APP_SERVE"},
|
|
|
|
GenericFlag{Name: "serve, s", Value: &Parser{}, EnvVar: "APP_SERVE"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"20", "30"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"20", "30"}) {
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"20", "30"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"20", "30"}) {
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
@ -953,10 +981,11 @@ func TestParseGenericFromEnvCascade(t *testing.T) {
|
|
|
|
Flags: []Flag{
|
|
|
|
Flags: []Flag{
|
|
|
|
GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
|
|
|
|
GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
Action: func(ctx *Context) error {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("foos"), &Parser{"99", "2000"}) {
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("foos"), &Parser{"99", "2000"}) {
|
|
|
|
t.Errorf("value not set from env")
|
|
|
|
t.Errorf("value not set from env")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
a.Run([]string{"run"})
|
|
|
|