1
0
mirror of https://github.com/go-task/task.git synced 2025-05-15 22:26:28 +02:00
task/taskfile/node_base.go

42 lines
780 B
Go
Raw Permalink Normal View History

package taskfile
type (
NodeOption func(*baseNode)
// baseNode is a generic node that implements the Parent() methods of the
2023-09-06 00:11:13 +00:00
// 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 00:11:13 +00:00
parent Node
dir string
}
)
func NewBaseNode(dir string, opts ...NodeOption) *baseNode {
node := &baseNode{
2023-09-06 00:11:13 +00: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
}
func (node *baseNode) Dir() string {
2024-02-13 01:07:00 +00:00
return node.dir
}