mirror of
https://github.com/charmbracelet/gum
synced 2024-05-19 06:37:00 +02:00
66993d8ef1
* chore: add linter configs & workflows * fix: ignore certain linter warnings * fix: mark errors as intentionally ignored * fix: avoid unnecessary conversion * fix: handle template/renderer errors * fix: mark intentionally unused code
38 lines
715 B
Go
38 lines
715 B
Go
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
|
|
}
|
|
|
|
var defaultIgnorePatterns = []string{"node_modules", ".git", "."}
|
|
|
|
func shouldIgnore(path string) bool {
|
|
for _, prefix := range defaultIgnorePatterns {
|
|
if strings.HasPrefix(path, prefix) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|