1
0
mirror of https://github.com/go-task/task.git synced 2025-09-16 09:26:16 +02:00

fix: optional includes

This commit is contained in:
Pete Davison
2023-09-06 00:11:13 +00:00
parent 220bf74a9e
commit 6b3f8e29bb
3 changed files with 11 additions and 25 deletions

View File

@@ -17,7 +17,6 @@ type Node interface {
Parent() Node
Location() string
Dir() string
Optional() bool
Remote() bool
ResolveEntrypoint(entrypoint string) (string, error)
ResolveDir(dir string) (string, error)

View File

@@ -2,22 +2,20 @@ package taskfile
type (
NodeOption func(*BaseNode)
// BaseNode is a generic node that implements the Parent() and Optional()
// 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 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 {
parent Node
optional bool
dir string
parent Node
dir string
}
)
func NewBaseNode(dir string, opts ...NodeOption) *BaseNode {
node := &BaseNode{
parent: nil,
optional: false,
dir: dir,
parent: nil,
dir: dir,
}
// Apply options
@@ -38,16 +36,6 @@ func (node *BaseNode) Parent() Node {
return node.parent
}
func WithOptional(optional bool) NodeOption {
return func(node *BaseNode) {
node.optional = optional
}
}
func (node *BaseNode) Optional() bool {
return node.optional
}
func (node *BaseNode) Dir() string {
return node.dir
}

View File

@@ -89,9 +89,6 @@ func (r *Reader) include(node Node) error {
var err error
vertex.Taskfile, err = r.readNode(node)
if err != nil {
if node.Optional() {
return nil
}
return err
}
@@ -129,9 +126,11 @@ func (r *Reader) include(node Node) error {
includeNode, err := NewNode(r.logger, entrypoint, dir, r.insecure, r.timeout,
WithParent(node),
WithOptional(include.Optional),
)
if err != nil {
if include.Optional {
return nil
}
return err
}