gum/internal/files/files.go

38 lines
715 B
Go
Raw Normal View History

package files
import (
"os"
"path/filepath"
"strings"
)
// List returns a list of all files in the current directory.
// It ignores the .git directory.
func List() []string {
var files []string
err := filepath.Walk(".",
func(path string, info os.FileInfo, err error) error {
if shouldIgnore(path) || info.IsDir() || err != nil {
return nil //nolint:nilerr
}
files = append(files, path)
return nil
})
if err != nil {
return []string{}
}
return files
}
2022-07-08 04:39:28 +02:00
var defaultIgnorePatterns = []string{"node_modules", ".git", "."}
func shouldIgnore(path string) bool {
2022-07-08 04:39:28 +02:00
for _, prefix := range defaultIgnorePatterns {
if strings.HasPrefix(path, prefix) {
return true
}
}
return false
}