From cb07aa408018eeedc5d3cf29e7b8f19d37421921 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 20 Mar 2026 11:20:55 -0700 Subject: [PATCH] flag: replace regexp use Commit ec05a8d3 introduces the only (non-test) user of regexp package. It is pretty easy to not use regexp here, so let's get rid of it. Signed-off-by: Kir Kolyshkin --- flag.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/flag.go b/flag.go index 1a65948ec4..1b849f1228 100644 --- a/flag.go +++ b/flag.go @@ -3,7 +3,6 @@ package cli import ( "context" "fmt" - "regexp" "slices" "strings" "time" @@ -17,11 +16,7 @@ const ( disableSliceFlagSeparator = false ) -var ( - slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano()) - - commaWhitespace = regexp.MustCompile("[, ]+.*") -) +var slPfx = fmt.Sprintf("sl:::%d:::", time.Now().UTC().UnixNano()) // GenerateShellCompletionFlag enables shell completion var GenerateShellCompletionFlag Flag = &BoolFlag{ @@ -202,7 +197,11 @@ func FlagNames(name string, aliases []string) []string { // 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". - ret = append(ret, commaWhitespace.ReplaceAllString(part, "")) + if i := strings.IndexAny(part, ", "); i >= 0 { + ret = append(ret, part[:i]) + } else { + ret = append(ret, part) + } } return ret