1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00
task/taskfile/node_base.go

42 lines
780 B
Go
Raw Normal View History

package taskfile
type (
NodeOption func(*BaseNode)
2023-09-06 02:11:13 +02:00
// BaseNode is a generic node that implements the Parent() methods of the
// NodeReader interface. It does not implement the Read() method and it
// designed to be embedded in other node types so that this boilerplate code
// does not need to be repeated.
BaseNode struct {
2023-09-06 02:11:13 +02:00
parent Node
dir string
}
)
func NewBaseNode(dir string, opts ...NodeOption) *BaseNode {
node := &BaseNode{
2023-09-06 02:11:13 +02:00
parent: nil,
dir: dir,
}
// Apply options
for _, opt := range opts {
opt(node)
}
return node
}
func WithParent(parent Node) NodeOption {
return func(node *BaseNode) {
node.parent = parent
}
}
func (node *BaseNode) Parent() Node {
return node.parent
}
2024-02-13 03:07:00 +02:00
func (node *BaseNode) Dir() string {
return node.dir
}