feat(globs): glob support for dump/restore, extracts some shared logic

This commit is contained in:
Lewis Wynne 2025-12-17 22:18:15 +00:00
parent 9869b663e2
commit 7890e9451d
9 changed files with 141 additions and 57 deletions

View file

@ -3,6 +3,7 @@ package cmd
import (
"strings"
"github.com/gobwas/glob"
"github.com/spf13/cobra"
)
@ -26,3 +27,28 @@ func parseGlobSeparators(cmd *cobra.Command) ([]rune, error) {
}
return []rune(sepStr), nil
}
func compileGlobMatchers(patterns []string, separators []rune) ([]glob.Glob, error) {
var matchers []glob.Glob
for _, pattern := range patterns {
m, err := glob.Compile(strings.ToLower(pattern), separators...)
if err != nil {
return nil, err
}
matchers = append(matchers, m)
}
return matchers, nil
}
func globMatch(matchers []glob.Glob, key string) bool {
if len(matchers) == 0 {
return true
}
lowered := strings.ToLower(key)
for _, m := range matchers {
if m.Match(lowered) {
return true
}
}
return false
}