diff --git a/build.go b/build.go index 7791c62..287beeb 100644 --- a/build.go +++ b/build.go @@ -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) } diff --git a/kong_test.go b/kong_test.go index f05fc18..4785dd0 100644 --- a/kong_test.go +++ b/kong_test.go @@ -467,6 +467,19 @@ func TestDuplicateNegatableLong(t *testing.T) { assert.EqualError(t, err, ".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 {