package cabret import ( "io/fs" "path/filepath" "github.com/aziis98/cabret/path" "golang.org/x/exp/slices" ) func FindFiles(excludePatterns ...string) ([]string, error) { // TODO: Use [filepath.Glob] instead of [*path.Pattern] concreteExcludePatterns := []*path.Pattern{} for _, rawPattern := range excludePatterns { pattern, err := path.ParsePattern(rawPattern) if err != nil { return nil, err } concreteExcludePatterns = append(concreteExcludePatterns, pattern) } paths := []string{} if err := filepath.Walk(".", func(p string, info fs.FileInfo, err error) error { if info.IsDir() { return nil } if slices.ContainsFunc(concreteExcludePatterns, func(pattern *path.Pattern) bool { ok, _, _ := pattern.Match(p) return ok }) { return nil } paths = append(paths, p) return nil }); err != nil { return nil, err } return paths, nil }