dropClashingAliases removes aliases from `aliases` that are already claimed by a flag in `userFlags` (either as a primary name or as one of its own aliases). Aliases equal to `selfName` are kept so the flag's primary name doesn't accidentally remove itself.
(aliases []string, userFlags []Flag, selfName string)
| 265 | // of its own aliases). Aliases equal to `selfName` are kept so the |
| 266 | // flag's primary name doesn't accidentally remove itself. |
| 267 | func dropClashingAliases(aliases []string, userFlags []Flag, selfName string) []string { |
| 268 | if len(aliases) == 0 || len(userFlags) == 0 { |
| 269 | return aliases |
| 270 | } |
| 271 | taken := map[string]struct{}{} |
| 272 | for _, f := range userFlags { |
| 273 | for _, n := range f.Names() { |
| 274 | taken[n] = struct{}{} |
| 275 | } |
| 276 | } |
| 277 | kept := aliases[:0:0] |
| 278 | for _, a := range aliases { |
| 279 | if a == selfName { |
| 280 | kept = append(kept, a) |
| 281 | continue |
| 282 | } |
| 283 | if _, ok := taken[a]; ok { |
| 284 | continue |
| 285 | } |
| 286 | kept = append(kept, a) |
| 287 | } |
| 288 | return kept |
| 289 | } |