filewalker

package
v0.1.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node struct {
	Type     NodeType
	Path     string
	Parent   *Node
	Children []*Node
}

Node represents a file or directory in the AST.

func (*Node) AllDescendants

func (n *Node) AllDescendants() []*Node

AllDescendants returns all descendant nodes recursively.

func (*Node) GetParent

func (n *Node) GetParent() *Node

GetParent returns the parent node.

func (*Node) GetPath

func (n *Node) GetPath() string

GetPath returns the path of the node.

func (*Node) GetType

func (n *Node) GetType() NodeType

GetType returns the type of the node (file or directory).

func (*Node) ImmediateChildren

func (n *Node) ImmediateChildren() []*Node

ImmediateChildren returns the immediate child nodes.

type NodeType

type NodeType int

NodeType represents the type of the node: file or directory.

const (
	FileNode NodeType = iota
	DirectoryNode
)

type VisitFunc

type VisitFunc func(w *Walker, node *Node) error

VisitFunc defines the function signature for pre- and post-visit callbacks.

type Walker

type Walker struct {
	FollowSymlinks bool
	// contains filtered or unexported fields
}

Walker traverses the file system and builds the AST.

func NewWalker

func NewWalker(opts ...WalkerOption) (*Walker, error)

NewWalker creates a new Walker with the provided options.

func (*Walker) GetNodeByPath

func (w *Walker) GetNodeByPath(path string) (*Node, error)

GetNodeByPath retrieves a node by its path.

func (*Walker) GetNodeByRelativePath

func (w *Walker) GetNodeByRelativePath(baseNode *Node, relativePath string) (*Node, error)

GetNodeByRelativePath retrieves a node by a path relative to a base node.

func (*Walker) Walk

func (w *Walker) Walk(paths []string, preVisit VisitFunc, postVisit VisitFunc) error

Walk traverses the file system or creates a virtual file tree from the given paths.

type WalkerOption

type WalkerOption func(*Walker)

WalkerOption defines a function type for configuring the Walker.

func WithFS

func WithFS(fsys fs.FS) WalkerOption

WithFS sets the file system for the Walker.

func WithFilter

func WithFilter(filter func(node *Node) bool) WalkerOption

WithFilter sets a filter function for the Walker.

func WithFollowSymlinks(follow bool) WalkerOption

WithFollowSymlinks sets whether the walker should follow symbolic links.

func WithPaths

func WithPaths(paths []string) WalkerOption

WithPaths sets the paths for the Walker.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL