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