mirror of
https://github.com/go-task/task.git
synced 2025-11-25 22:32:55 +02:00
fix: optional includes
This commit is contained in:
@@ -17,7 +17,6 @@ type Node interface {
|
|||||||
Parent() Node
|
Parent() Node
|
||||||
Location() string
|
Location() string
|
||||||
Dir() string
|
Dir() string
|
||||||
Optional() bool
|
|
||||||
Remote() bool
|
Remote() bool
|
||||||
ResolveEntrypoint(entrypoint string) (string, error)
|
ResolveEntrypoint(entrypoint string) (string, error)
|
||||||
ResolveDir(dir string) (string, error)
|
ResolveDir(dir string) (string, error)
|
||||||
|
|||||||
@@ -2,22 +2,20 @@ package taskfile
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
NodeOption func(*BaseNode)
|
NodeOption func(*BaseNode)
|
||||||
// BaseNode is a generic node that implements the Parent() and Optional()
|
// BaseNode is a generic node that implements the Parent() methods of the
|
||||||
// methods of the NodeReader interface. It does not implement the Read() method
|
// NodeReader interface. It does not implement the Read() method and it
|
||||||
// and it designed to be embedded in other node types so that this boilerplate
|
// designed to be embedded in other node types so that this boilerplate code
|
||||||
// code does not need to be repeated.
|
// does not need to be repeated.
|
||||||
BaseNode struct {
|
BaseNode struct {
|
||||||
parent Node
|
parent Node
|
||||||
optional bool
|
dir string
|
||||||
dir string
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewBaseNode(dir string, opts ...NodeOption) *BaseNode {
|
func NewBaseNode(dir string, opts ...NodeOption) *BaseNode {
|
||||||
node := &BaseNode{
|
node := &BaseNode{
|
||||||
parent: nil,
|
parent: nil,
|
||||||
optional: false,
|
dir: dir,
|
||||||
dir: dir,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply options
|
// Apply options
|
||||||
@@ -38,16 +36,6 @@ func (node *BaseNode) Parent() Node {
|
|||||||
return node.parent
|
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 {
|
func (node *BaseNode) Dir() string {
|
||||||
return node.dir
|
return node.dir
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,9 +89,6 @@ func (r *Reader) include(node Node) error {
|
|||||||
var err error
|
var err error
|
||||||
vertex.Taskfile, err = r.readNode(node)
|
vertex.Taskfile, err = r.readNode(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if node.Optional() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,9 +126,11 @@ func (r *Reader) include(node Node) error {
|
|||||||
|
|
||||||
includeNode, err := NewNode(r.logger, entrypoint, dir, r.insecure, r.timeout,
|
includeNode, err := NewNode(r.logger, entrypoint, dir, r.insecure, r.timeout,
|
||||||
WithParent(node),
|
WithParent(node),
|
||||||
WithOptional(include.Optional),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if include.Optional {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user