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
794 B
Go

package cabret
import (
"io/fs"
"path/filepath"
"github.com/aziis98/cabret/path"
"golang.org/x/exp/slices"
)
func FindFiles(excludes []string) ([]string, error) {
paths := []string{}
excludeMatchers := []*path.Pattern{}
for _, p := range excludes {
m, err := path.ParsePattern(p)
if err != nil {
return nil, err
}
excludeMatchers = append(excludeMatchers, m)
}
if err := filepath.Walk(".", func(p string, info fs.FileInfo, err error) error {
if info.IsDir() {
return nil
}
excluded := slices.ContainsFunc(excludeMatchers, func(excludePattern *path.Pattern) bool {
ok, _, _ := excludePattern.Match(p)
return ok
})
if excluded {
return nil
}
paths = append(paths, p)
return nil
}); err != nil {
return nil, err
}
return paths, nil
}