Documentation
¶
Index ¶
- Constants
- func CollectFiles(paths []string, shouldIgnore func(path string) bool) ([]string, error)
- func CollectFilesFromTree(node *TreeNode, basePath string, files *[]string)
- func ListDirectory(path string, shouldIgnore func(string) bool) ([]string, error)
- func Matches(path string, patterns []string) (bool, error)
- func WalkFiles(ctx context.Context, root string, opts WalkFilesOptions) ([]string, error)
- type TreeNode
- type VCSMatcher
- type WalkFilesOptions
Constants ¶
const DefaultMaxFiles = 20000
DefaultMaxFiles is the default cap for file walking to prevent runaway scans.
Variables ¶
This section is empty.
Functions ¶
func CollectFiles ¶
CollectFiles recursively collects all files from given paths. Supports glob patterns (via doublestar), directories, and individual files. Skips paths that don't exist instead of returning an error. Optional shouldIgnore filter can exclude files/directories (return true to skip).
func CollectFilesFromTree ¶
CollectFilesFromTree recursively collects file paths from a DirectoryTree. Pass basePath="" for relative paths, or a parent directory for absolute paths.
func ListDirectory ¶
func Matches ¶
Matches reports whether the given path matches any configured path or glob pattern. Useful for file watchers to determine if a changed file matches configured patterns.
func WalkFiles ¶ added in v1.20.6
WalkFiles walks the directory tree starting at root and returns a list of file paths. It is bounded by MaxFiles (defaults to DefaultMaxFiles) and skips hidden directories and known heavy directories like node_modules, vendor, etc. The walk respects context cancellation.
Types ¶
type TreeNode ¶
type VCSMatcher ¶
type VCSMatcher struct {
// contains filtered or unexported fields
}
VCSMatcher handles VCS ignore pattern matching for a git repository
func NewVCSMatcher ¶
func NewVCSMatcher(basePath string) (*VCSMatcher, error)
NewVCSMatcher creates a new VCS matcher for the given path. It searches for a git repository and loads .gitignore patterns. Returns (nil, nil) if no git repository is found - this is not an error. Results are cached by repository root path to avoid repeated parsing.
func (*VCSMatcher) RepoRoot ¶
func (m *VCSMatcher) RepoRoot() string
RepoRoot returns the repository root path for this matcher
func (*VCSMatcher) ShouldIgnore ¶
func (m *VCSMatcher) ShouldIgnore(path string) bool
ShouldIgnore checks if a path should be ignored based on VCS rules. It checks both .git directories and .gitignore patterns.
type WalkFilesOptions ¶ added in v1.20.6
type WalkFilesOptions struct {
// MaxFiles is the maximum number of files to return (0 = no limit, but defaults to DefaultMaxFiles).
MaxFiles int
// MaxDepth is the maximum directory depth to descend (0 = unlimited).
// Depth 1 means only root directory, depth 2 means root + immediate children, etc.
MaxDepth int
// ShouldIgnore is an optional function to filter out paths (return true to skip).
ShouldIgnore func(path string) bool
}
WalkFilesOptions configures the bounded file walker.