esr/internal/glob/matcher.go
2024-10-09 14:22:28 -04:00

33 lines
610 B
Go

package glob
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/bmatcuk/doublestar/v3"
)
func GlobFiles(pattern string) ([]string, error) {
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("failed to get current working directory: %w", err)
}
matches, err := doublestar.Glob(filepath.Join(cwd, pattern))
if err != nil {
return nil, fmt.Errorf("failed to match pattern: %w", err)
}
for i, match := range matches {
matches[i] = strings.TrimPrefix(match, cwd)
}
for i, match := range matches {
matches[i] = strings.TrimPrefix(match, "/")
}
return matches, nil
}