8000 Use withEnvHint instead of custom func · urfave/cli@6b738dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b738dc

Browse files
committed
Use withEnvHint instead of custom func
1 parent e320fd8 commit 6b738dc

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

flag_test.go

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"os"
99
"reflect"
1010
"regexp"
11-
"runtime"
1211
"strings"
1312
"testing"
1413
"time"
@@ -507,7 +506,7 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
507506
fl := &StringFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_FOO"}}
508507
output := fl.String()
509508

510-
expectedSuffix := suffixForEnv("APP_FOO")
509+
expectedSuffix := withEnvHint([]string{"APP_FOO"}, "")
511510
if !strings.HasSuffix(output, expectedSuffix) {
512511
t.Errorf("%s does not end with"+expectedSuffix, output)
513512
}
@@ -596,7 +595,7 @@ func TestPathFlagWithEnvVarHelpOutput(t *testing.T) {
596595
fl := &PathFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_PATH"}}
597596
output := fl.String()
598597

599-
expectedSuffix := suffixForEnv("APP_PATH")
598+
expectedSuffix := withEnvHint([]string{"APP_PATH"}, "")
600599
if !strings.HasSuffix(output, expectedSuffix) {
601600
t.Errorf("%s does not end with"+expectedSuffix, output)
602601
}
@@ -690,7 +689,7 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
690689
fl := &StringSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_QWWX"}}
691690
output := fl.String()
692691

693-
expectedSuffix := suffixForEnv("APP_QWWX")
692+
expectedSuffix := withEnvHint([]string{"APP_QWWX"}, "")
694693
if !strings.HasSuffix(output, expectedSuffix) {
695694
t.Errorf("%q does not end with"+expectedSuffix, output)
696695
}
@@ -788,7 +787,7 @@ func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
788787
fl := &IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
789788
output := fl.String()
790789

791-
expectedSuffix := suffixForEnv("APP_BAR")
790+
expectedSuffix := withEnvHint([]string{"APP_BAR"}, "")
792791
if !strings.HasSuffix(output, expectedSuffix) {
793792
t.Errorf("%s does not end with"+expectedSuffix, output)
794793
}
@@ -847,21 +846,13 @@ func TestInt64FlagWithEnvVarHelpOutput(t *testing.T) {
847846
fl := IntFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
848847
output := fl.String()
849848

850-
expectedSuffix := suffixForEnv("APP_BAR")
849+
expectedSuffix := withEnvHint([]string{"APP_BAR"}, "")
851850
if !strings.HasSuffix(output, expectedSuffix) {
852851
t.Errorf("%s does not end with"+expectedSuffix, output)
853852
}
854853
}
855854
}
856855

857-
func suffixForEnv(s string) string {
858-
expectedSuffix := fmt.Sprintf(" [$%s]", s)
859-
if runtime.GOOS == "windows" {
860-
expectedSuffix = fmt.Sprintf(" [%s%s%s]", "%", s, "%")
861-
}
862-
return expectedSuffix
863-
}
864-
865856
func TestInt64FlagValueFromContext(t *testing.T) {
866857
set := flag.NewFlagSet("test", 0)
867858
set.Int64("myflag", 42, "doc")
@@ -903,7 +894,7 @@ func TestUintFlagWithEnvVarHelpOutput(t *testing.T) {
903894
fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
904895
output := fl.String()
905896

906-
expectedSuffix := suffixForEnv("APP_BAR")
897+
expectedSuffix := withEnvHint([]string{"APP_BAR"}, "")
907898
if !strings.HasSuffix(output, expectedSuffix) {
908899
t.Errorf("%s does not end with"+expectedSuffix, output)
909900
}
@@ -951,7 +942,7 @@ func TestUint64FlagWithEnvVarHelpOutput(t *testing.T) {
951942
fl := UintFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
952943
output := fl.String()
953944

954-
expectedSuffix := suffixForEnv("APP_BAR")
945+
expectedSuffix := withEnvHint([]string{"APP_BAR"}, "")
955946
if !strings.HasSuffix(output, expectedSuffix) {
956947
t.Errorf("%s does not end with"+expectedSuffix, output)
957948
}
@@ -999,7 +990,7 @@ func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
999990
fl := &DurationFlag{Name: test.name, EnvVars: []string{"APP_BAR"}}
1000991
output := fl.String()
1001992

1002-
expectedSuffix := suffixForEnv("APP_BAR")
993+
expectedSuffix := withEnvHint([]string{"APP_BAR"}, "")
1003994
if !strings.HasSuffix(output, expectedSuffix) {
1004995
t.Errorf("%s does not end with"+expectedSuffix, output)
1005996
}
@@ -1056,7 +1047,7 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
10561047
fl := &IntSliceFlag{Name: test.name, Aliases: test.aliases, Value: test.value, EnvVars: []string{"APP_SMURF"}}
10571048
output := fl.String()
10581049

1059-
expectedSuffix := suffixForEnv("APP_SMURF")
1050+
expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "")
10601051
if !strings.HasSuffix(output, expectedSuffix) {
10611052
t.Errorf("%q does not end with"+expectedSuffix, output)
10621053
}
@@ -1192,7 +1183,7 @@ func TestInt64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
11921183
fl := Int64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
11931184
output := fl.String()
11941185

1195-
expectedSuffix := suffixForEnv("APP_SMURF")
1186+
expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "")
11961187
if !strings.HasSuffix(output, expectedSuffix) {
11971188
t.Errorf("%q does not end with"+expectedSuffix, output)
11981189
}
@@ -1343,7 +1334,7 @@ func TestUintSliceFlagWithEnvVarHelpOutput(t *testing.T) {
13431334
fl := UintSliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
13441335
output := fl.String()
13451336

1346-
expectedSuffix := suffixForEnv("APP_SMURF")
1337+
expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "")
13471338
if !strings.HasSuffix(output, expectedSuffix) {
13481339
t.Errorf("%q does not end with"+expectedSuffix, output)
13491340
}
@@ -1486,7 +1477,7 @@ func TestUint64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
14861477
fl := Uint64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
14871478
output := fl.String()
14881479

1489-
expectedSuffix := suffixForEnv("APP_SMURF")
1480+
expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "")
14901481
if !strings.HasSuffix(output, expectedSuffix) {
14911482
t.Errorf("%q does not end with"+expectedSuffix, output)
14921483
}
@@ -1625,7 +1616,7 @@ func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
16251616
fl := &Float64Flag{Name: test.name, EnvVars: []string{"APP_BAZ"}}
16261617
output := fl.String()
16271618

1628-
expectedSuffix := suffixForEnv("APP_BAZ")
1619+
expectedSuffix := withEnvHint([]string{"APP_BAZ"}, "")
16291620
if !strings.HasSuffix(output, expectedSuffix) {
16301621
t.Errorf("%s does not end with"+expectedSuffix, output)
16311622
}
@@ -1682,7 +1673,7 @@ func TestFloat64SliceFlagWithEnvVarHelpOutput(t *testing.T) {
16821673
fl := Float64SliceFlag{Name: test.name, Value: test.value, EnvVars: []string{"APP_SMURF"}}
16831674
output := fl.String()
16841675

1685-
expectedSuffix := suffixForEnv("APP_SMURF")
1676+
expectedSuffix := withEnvHint([]string{"APP_SMURF"}, "")
16861677
if !strings.HasSuffix(output, expectedSuffix) {
16871678
t.Errorf("%q does not end with"+expectedSuffix, output)
16881679
}
@@ -1802,7 +1793,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
18021793
fl := &GenericFlag{Name: test.name, EnvVars: []string{"APP_ZAP"}}
18031794
output := fl.String()
18041795

1805-
expectedSuffix := suffixForEnv("APP_ZAP")
1796+
expectedSuffix := withEnvHint([]string{"APP_ZAP"}, "")
18061797
if !strings.HasSuffix(output, expectedSuffix) {
18071798
t.Errorf("%s does not end with"+expectedSuffix, output)
18081799
}

0 commit comments

Comments
 (0)
0