Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,26 @@ func visibleFlags(fl []Flag) []Flag {
}

func FlagNames(name string, aliases []string) []string {
var ret []string

for _, part := range append([]string{name}, aliases...) {
// v1 -> v2 migration warning zone:
// Strip off anything after the first found comma or space, which
// *hopefully* makes it a tiny bit more obvious that unexpected behavior is
// caused by using the v1 form of stringly typed "Name".
if i := strings.IndexAny(part, ", "); i >= 0 {
ret = append(ret, part[:i])
} else {
ret = append(ret, part)
}
ret := make([]string, 0, len(aliases)+1)
ret = append(ret, stripV1Name(name))
for _, part := range aliases {
ret = append(ret, stripV1Name(part))
}

return ret
}

// stripV1Name is the v1 -> v2 migration warning zone:
// Strip off anything after the first found comma or space, which
// *hopefully* makes it a tiny bit more obvious that unexpected behavior is
// caused by using the v1 form of stringly typed "Name".
func stripV1Name(part string) string {
if i := strings.IndexAny(part, ", "); i >= 0 {
return part[:i]
}
return part
}

func hasFlag(flags []Flag, fl Flag) bool {
return slices.Contains(flags, fl)
}
Expand Down
Loading