Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1ed3859

Browse files
committedApr 10, 2025
cli-plugins/manager: use lazyregexp to compile regexes on first use
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 7fde1f7 commit 1ed3859

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎cli-plugins/manager/plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11-
"regexp"
1211
"strings"
1312

1413
"github.com/docker/cli/cli-plugins/metadata"
14+
"github.com/docker/cli/internal/lazyregexp"
1515
"github.com/spf13/cobra"
1616
)
1717

18-
var pluginNameRe = regexp.MustCompile("^[a-z][a-z0-9]*$")
18+
var pluginNameRe = lazyregexp.New("^[a-z][a-z0-9]*$")
1919

2020
// Plugin represents a potential plugin with all it's metadata.
2121
type Plugin struct {

‎internal/lazyregexp/lazyregexp.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (r *Regexp) ReplaceAllLiteralString(src, repl string) string {
7575
return r.re().ReplaceAllLiteralString(src, repl)
7676
}
7777

78+
func (r *Regexp) String() string {
79+
return r.re().String()
80+
}
81+
7882
func (r *Regexp) SubexpNames() []string {
7983
return r.re().SubexpNames()
8084
}

0 commit comments

Comments
 (0)
Please sign in to comment.