|
|
|
@ -4,9 +4,9 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"reflect"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"runtime"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var boolFlagTests = []struct {
|
|
|
|
@ -64,7 +64,7 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
expectedSuffix = " [%APP_FOO%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%s does not end with" + expectedSuffix, output)
|
|
|
|
|
t.Errorf("%s does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -120,7 +120,7 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
expectedSuffix = " [%APP_QWWX%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%q does not end with" + expectedSuffix, output)
|
|
|
|
|
t.Errorf("%q does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -157,7 +157,7 @@ func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
expectedSuffix = " [%APP_BAR%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%s does not end with" + expectedSuffix, output)
|
|
|
|
|
t.Errorf("%s does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -194,7 +194,7 @@ func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
expectedSuffix = " [%APP_BAR%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%s does not end with" + expectedSuffix, output)
|
|
|
|
|
t.Errorf("%s does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -238,7 +238,7 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
expectedSuffix = " [%APP_SMURF%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%q does not end with" + expectedSuffix, output)
|
|
|
|
|
t.Errorf("%q does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -275,7 +275,7 @@ func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
expectedSuffix = " [%APP_BAZ%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%s does not end with" + expectedSuffix, output)
|
|
|
|
|
t.Errorf("%s does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -313,7 +313,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
|
|
|
|
expectedSuffix = " [%APP_ZAP%]"
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasSuffix(output, expectedSuffix) {
|
|
|
|
|
t.Errorf("%s does not end with" + expectedSuffix, output)
|
|
|
|
|
t.Errorf("%s does not end with"+expectedSuffix, output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -323,13 +323,14 @@ func TestParseMultiString(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
StringFlag{Name: "serve, s"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.String("serve") != "10" {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.String("s") != "10" {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run", "-s", "10"})
|
|
|
|
|
}
|
|
|
|
@ -343,10 +344,11 @@ func TestParseDestinationString(t *testing.T) {
|
|
|
|
|
Destination: &dest,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if dest != "10" {
|
|
|
|
|
t.Errorf("expected destination String 10")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "--dest", "10"})
|
|
|
|
@ -359,13 +361,14 @@ func TestParseMultiStringFromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
StringFlag{Name: "count, c", EnvVar: "APP_COUNT"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.String("count") != "20" {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.String("c") != "20" {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
@ -377,13 +380,14 @@ func TestParseMultiStringFromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
StringFlag{Name: "count, c", EnvVar: "COMPAT_COUNT,APP_COUNT"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.String("count") != "20" {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.String("c") != "20" {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
@ -393,13 +397,14 @@ func TestParseMultiStringSlice(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
StringSliceFlag{Name: "serve, s", Value: &StringSlice{}},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("serve"), []string{"10", "20"}) {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("s"), []string{"10", "20"}) {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run", "-s", "10", "-s", "20"})
|
|
|
|
|
}
|
|
|
|
@ -412,13 +417,14 @@ func TestParseMultiStringSliceFromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "APP_INTERVALS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("intervals"), []string{"20", "30", "40"}) {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("i"), []string{"20", "30", "40"}) {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
@ -431,13 +437,14 @@ func TestParseMultiStringSliceFromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
StringSliceFlag{Name: "intervals, i", Value: &StringSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("intervals"), []string{"20", "30", "40"}) {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.StringSlice("i"), []string{"20", "30", "40"}) {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
@ -447,13 +454,14 @@ func TestParseMultiInt(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
IntFlag{Name: "serve, s"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Int("serve") != 10 {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Int("s") != 10 {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "-s", "10"})
|
|
|
|
@ -468,10 +476,11 @@ func TestParseDestinationInt(t *testing.T) {
|
|
|
|
|
Destination: &dest,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if dest != 10 {
|
|
|
|
|
t.Errorf("expected destination Int 10")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "--dest", "10"})
|
|
|
|
@ -484,13 +493,14 @@ func TestParseMultiIntFromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
IntFlag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Int("timeout") != 10 {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Int("t") != 10 {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -503,13 +513,14 @@ func TestParseMultiIntFromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
IntFlag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Int("timeout") != 10 {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Int("t") != 10 {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -520,13 +531,14 @@ func TestParseMultiIntSlice(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
IntSliceFlag{Name: "serve, s", Value: &IntSlice{}},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("serve"), []int{10, 20}) {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("s"), []int{10, 20}) {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run", "-s", "10", "-s", "20"})
|
|
|
|
|
}
|
|
|
|
@ -539,13 +551,14 @@ func TestParseMultiIntSliceFromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "APP_INTERVALS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("intervals"), []int{20, 30, 40}) {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("i"), []int{20, 30, 40}) {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
@ -558,13 +571,14 @@ func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
IntSliceFlag{Name: "intervals, i", Value: &IntSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("intervals"), []int{20, 30, 40}) {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.IntSlice("i"), []int{20, 30, 40}) {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}).Run([]string{"run"})
|
|
|
|
|
}
|
|
|
|
@ -574,13 +588,14 @@ func TestParseMultiFloat64(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
Float64Flag{Name: "serve, s"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Float64("serve") != 10.2 {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Float64("s") != 10.2 {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "-s", "10.2"})
|
|
|
|
@ -595,10 +610,11 @@ func TestParseDestinationFloat64(t *testing.T) {
|
|
|
|
|
Destination: &dest,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if dest != 10.2 {
|
|
|
|
|
t.Errorf("expected destination Float64 10.2")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "--dest", "10.2"})
|
|
|
|
@ -611,13 +627,14 @@ func TestParseMultiFloat64FromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
Float64Flag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Float64("timeout") != 15.5 {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Float64("t") != 15.5 {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -630,13 +647,14 @@ func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Float64("timeout") != 15.5 {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Float64("t") != 15.5 {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -647,13 +665,14 @@ func TestParseMultiBool(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
BoolFlag{Name: "serve, s"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Bool("serve") != true {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Bool("s") != true {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "--serve"})
|
|
|
|
@ -668,10 +687,11 @@ func TestParseDestinationBool(t *testing.T) {
|
|
|
|
|
Destination: &dest,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if dest != true {
|
|
|
|
|
t.Errorf("expected destination Bool true")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "--dest"})
|
|
|
|
@ -684,13 +704,14 @@ func TestParseMultiBoolFromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
BoolFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Bool("debug") != true {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Bool("d") != true {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -703,13 +724,14 @@ func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
BoolFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.Bool("debug") != true {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if ctx.Bool("d") != true {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -720,13 +742,14 @@ func TestParseMultiBoolT(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
BoolTFlag{Name: "serve, s"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.BoolT("serve") != true {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if ctx.BoolT("s") != true {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "--serve"})
|
|
|
|
@ -741,10 +764,11 @@ func TestParseDestinationBoolT(t *testing.T) {
|
|
|
|
|
Destination: &dest,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if dest != true {
|
|
|
|
|
t.Errorf("expected destination BoolT true")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "--dest"})
|
|
|
|
@ -757,13 +781,14 @@ func TestParseMultiBoolTFromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
BoolTFlag{Name: "debug, d", EnvVar: "APP_DEBUG"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.BoolT("debug") != false {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if ctx.BoolT("d") != false {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -776,13 +801,14 @@ func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if ctx.BoolT("debug") != false {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if ctx.BoolT("d") != false {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -811,13 +837,14 @@ func TestParseGeneric(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
GenericFlag{Name: "serve, s", Value: &Parser{}},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"10", "20"}) {
|
|
|
|
|
t.Errorf("main name not set")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"10", "20"}) {
|
|
|
|
|
t.Errorf("short name not set")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run", "-s", "10,20"})
|
|
|
|
@ -830,13 +857,14 @@ func TestParseGenericFromEnv(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
GenericFlag{Name: "serve, s", Value: &Parser{}, EnvVar: "APP_SERVE"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"20", "30"}) {
|
|
|
|
|
t.Errorf("main name not set from env")
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"20", "30"}) {
|
|
|
|
|
t.Errorf("short name not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
@ -849,10 +877,11 @@ func TestParseGenericFromEnvCascade(t *testing.T) {
|
|
|
|
|
Flags: []Flag{
|
|
|
|
|
GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
|
|
|
|
|
},
|
|
|
|
|
Action: func(ctx *Context) {
|
|
|
|
|
Action: func(ctx *Context) int {
|
|
|
|
|
if !reflect.DeepEqual(ctx.Generic("foos"), &Parser{"99", "2000"}) {
|
|
|
|
|
t.Errorf("value not set from env")
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
a.Run([]string{"run"})
|
|
|
|
|