Skip to content

Commit

Permalink
fix required/xor behavior w/ > 2 flags
Browse files Browse the repository at this point in the history
  • Loading branch information
pyqlsa authored and alecthomas committed Jan 29, 2022
1 parent e497001 commit ab085f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,8 @@ func checkMissingFlags(flags []*Flag) error {
missing = append(missing, flag.Summary())
}
}
for _, flags := range xorGroup {
if len(flags) > 1 {
for xor, flags := range xorGroup {
if !xorGroupSet[xor] && len(flags) > 1 {
missing = append(missing, strings.Join(flags, " or "))
}
}
Expand Down
4 changes: 4 additions & 0 deletions kong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,10 @@ func TestXorRequiredMany(t *testing.T) {
_, err := p.Parse([]string{"--one"})
require.NoError(t, err)

p = mustNew(t, &cli)
_, err = p.Parse([]string{"--three"})
require.NoError(t, err)

p = mustNew(t, &cli)
_, err = p.Parse([]string{})
require.EqualError(t, err, "missing flags: --one or --two or --three")
Expand Down

0 comments on commit ab085f7

Please sign in to comment.