Skip to content

Commit 1043857

Browse files
authored
Merge pull request #446 from spf13/fix-backwards-compat
fix: Restore ParseErrorsWhitelist name for now
2 parents b9c16fa + 7412009 commit 1043857

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

flag.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ type ParseErrorsAllowlist struct {
143143
UnknownFlags bool
144144
}
145145

146+
// DEPRECATED: please use ParseErrorsAllowlist instead
147+
// This type will be removed in a future release
148+
type ParseErrorsWhitelist = ParseErrorsAllowlist
149+
146150
// NormalizedName is a flag name that has been normalized according to rules
147151
// for the FlagSet (e.g. making '-' and '_' equivalent).
148152
type NormalizedName string
@@ -161,6 +165,10 @@ type FlagSet struct {
161165
// ParseErrorsAllowlist is used to configure an allowlist of errors
162166
ParseErrorsAllowlist ParseErrorsAllowlist
163167

168+
// DEPRECATED: please use ParseErrorsAllowlist instead
169+
// This field will be removed in a future release
170+
ParseErrorsWhitelist ParseErrorsAllowlist
171+
164172
name string
165173
parsed bool
166174
actual map[NormalizedName]*Flag
@@ -984,6 +992,8 @@ func (f *FlagSet) parseLongArg(s string, args []string, fn parseFunc) (a []strin
984992
case name == "help":
985993
f.usage()
986994
return a, ErrHelp
995+
case f.ParseErrorsWhitelist.UnknownFlags:
996+
fallthrough
987997
case f.ParseErrorsAllowlist.UnknownFlags:
988998
// --unknown=unknownval arg ...
989999
// we do not want to lose arg in this case
@@ -1042,6 +1052,8 @@ func (f *FlagSet) parseSingleShortArg(shorthands string, args []string, fn parse
10421052
f.usage()
10431053
err = ErrHelp
10441054
return
1055+
case f.ParseErrorsWhitelist.UnknownFlags:
1056+
fallthrough
10451057
case f.ParseErrorsAllowlist.UnknownFlags:
10461058
// '-f=arg arg ...'
10471059
// we do not want to lose arg in this case

flag_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,11 @@ func testParseAll(f *FlagSet, t *testing.T) {
447447
}
448448
}
449449

450-
func testParseWithUnknownFlags(f *FlagSet, t *testing.T) {
450+
func testParseWithUnknownFlags(f *FlagSet, t *testing.T, setUnknownFlags func(f *FlagSet)) {
451451
if f.Parsed() {
452452
t.Error("f.Parse() = true before Parse")
453453
}
454-
f.ParseErrorsAllowlist.UnknownFlags = true
454+
setUnknownFlags(f)
455455

456456
f.BoolP("boola", "a", false, "bool value")
457457
f.BoolP("boolb", "b", false, "bool2 value")
@@ -649,7 +649,12 @@ func TestParseAll(t *testing.T) {
649649

650650
func TestIgnoreUnknownFlags(t *testing.T) {
651651
ResetForTesting(func() { t.Error("bad parse") })
652-
testParseWithUnknownFlags(GetCommandLine(), t)
652+
testParseWithUnknownFlags(GetCommandLine(), t, func(f *FlagSet) { f.ParseErrorsAllowlist.UnknownFlags = true })
653+
}
654+
655+
func TestIgnoreUnknownFlagsBackwardsCompat(t *testing.T) {
656+
ResetForTesting(func() { t.Error("bad parse") })
657+
testParseWithUnknownFlags(GetCommandLine(), t, func(f *FlagSet) { f.ParseErrorsWhitelist.UnknownFlags = true })
653658
}
654659

655660
func TestFlagSetParse(t *testing.T) {

0 commit comments

Comments
 (0)