mirror of
				https://github.com/go-task/task.git
				synced 2025-10-30 23:58:01 +02:00 
			
		
		
		
	fix: optional includes
This commit is contained in:
		| @@ -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) | ||||
|   | ||||
| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
| 			} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user