2023-12-29 22:32:03 +02:00
|
|
|
package taskfile
|
2023-09-02 22:24:01 +02:00
|
|
|
|
2023-09-12 23:42:54 +02:00
|
|
|
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.
|
2023-09-12 23:42:54 +02:00
|
|
|
BaseNode struct {
|
2023-09-06 02:11:13 +02:00
|
|
|
parent Node
|
|
|
|
dir string
|
2023-09-12 23:42:54 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2024-03-04 20:00:28 +02:00
|
|
|
func NewBaseNode(dir string, opts ...NodeOption) *BaseNode {
|
2023-09-12 23:42:54 +02:00
|
|
|
node := &BaseNode{
|
2023-09-06 02:11:13 +02:00
|
|
|
parent: nil,
|
|
|
|
dir: dir,
|
2023-09-12 23:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply options
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(node)
|
|
|
|
}
|
|
|
|
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithParent(parent Node) NodeOption {
|
|
|
|
return func(node *BaseNode) {
|
|
|
|
node.parent = parent
|
|
|
|
}
|
2023-09-02 22:24:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *BaseNode) Parent() Node {
|
|
|
|
return node.parent
|
|
|
|
}
|
|
|
|
|
2024-02-13 03:07:00 +02:00
|
|
|
func (node *BaseNode) Dir() string {
|
|
|
|
return node.dir
|
|
|
|
}
|