Skip to content

Commit

Permalink
fix: allow duplicate custom negated flags
Browse files Browse the repository at this point in the history
Fixes #456
  • Loading branch information
alecthomas committed Sep 12, 2024
1 parent 9924ec4 commit 26c1c9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 13 additions & 0 deletions kong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 26c1c9a

Please sign in to comment.