Fix xor + required combo.

See #112.
This commit is contained in:
Alec Thomas
2021-07-11 21:23:18 +10:00
parent 8b2821cc24
commit cfbe844aa4
2 changed files with 24 additions and 0 deletions
+9
View File
@@ -743,14 +743,23 @@ func (c *Context) PrintUsage(summary bool) error {
}
func checkMissingFlags(flags []*Flag) error {
xorGroupSet := map[string]bool{}
xorGroup := map[string][]string{}
missing := []string{}
for _, flag := range flags {
if flag.Set {
for _, xor := range flag.Xor {
xorGroupSet[xor] = true
}
}
if !flag.Required || flag.Set {
continue
}
if len(flag.Xor) > 0 {
for _, xor := range flag.Xor {
if xorGroupSet[xor] {
continue
}
xorGroup[xor] = append(xorGroup[xor], flag.Summary())
}
} else {