You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
891 B
Go

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
}