boolFlags returns a map with a true value for every flag name that maps to a boolean field. This is needed so that bool flags can be properly set with their shorthand syntax.
(obj any)
| 70 | // that maps to a boolean field. This is needed so that bool |
| 71 | // flags can be properly set with their shorthand syntax. |
| 72 | func boolFlags(obj any) map[string]bool { |
| 73 | fields := &fields{} |
| 74 | addFields(obj, fields, addAllFields) |
| 75 | |
| 76 | res := map[string]bool{} |
| 77 | |
| 78 | for _, kv := range fields.Order { |
| 79 | f := kv.Value |
| 80 | |
| 81 | if f.Field.Type.Kind() != reflect.Bool { // we only care about bools here |
| 82 | continue |
| 83 | } |
| 84 | |
| 85 | // we need all cases of both normal and "no" version for all names |
| 86 | for _, name := range f.Names { |
| 87 | for _, cnms := range allCases(name) { |
| 88 | res[cnms] = true |
| 89 | } |
| 90 | for _, cnms := range allCases("No" + name) { |
| 91 | res[cnms] = true |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | return res |
| 96 | } |
| 97 | |
| 98 | // getArgs processes the given args using the given map of bool flags, |
| 99 | // which should be obtained through [boolFlags]. It returns the leftover |