fix: allow duplicate custom negated flags

Fixes #456
This commit is contained in:
Alec Thomas
2024-09-12 12:05:09 +10:00
parent 9924ec4461
commit 26c1c9ad05
2 changed files with 16 additions and 0 deletions
+3
View File
@@ -173,6 +173,9 @@ MAIN:
if flag.Short != 0 {
delete(seenFlags, "-"+string(flag.Short))
}
if negFlag := negatableFlagName(flag.Name, flag.Tag.Negatable); negFlag != "" {
delete(seenFlags, negFlag)
}
for _, aflag := range flag.Aliases {
delete(seenFlags, "--"+aflag)
}
+13
View File
@@ -467,6 +467,19 @@ func TestDuplicateNegatableLong(t *testing.T) {
assert.EqualError(t, err, "<anonymous struct>.Two: duplicate negation flag --one")
}
func TestDuplicateNegatableFlagsInSubcommands(t *testing.T) {
cli2 := struct {
Sub struct {
Negated bool `negatable:"nope-"`
} `cmd:""`
Sub2 struct {
Negated bool `negatable:"nope-"`
} `cmd:""`
}{}
_, err := kong.New(&cli2)
assert.NoError(t, err)
}
func TestExistingNoFlag(t *testing.T) {
var cli struct {
Cmd struct {