MCPcopy
hub / github.com/urfave/cli / dropClashingAliases

Function dropClashingAliases

command_setup.go:267–289  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

265// of its own aliases). Aliases equal to `selfName` are kept so the
266// flag's primary name doesn't accidentally remove itself.
267func 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}

Callers 2

setupDefaultsMethod · 0.85
TestDropClashingAliasesFunction · 0.85

Calls 1

NamesMethod · 0.65

Tested by 1

TestDropClashingAliasesFunction · 0.68