mirror of
https://github.com/go-task/task.git
synced 2026-06-24 05:05:49 +00:00
feat: node refactor (#1316)
* refactor: node reader interface * refactor: rewrite Taskfile() as anon recursive func * chore: NewNodeFromIncludedTaskfile * chore: changelog
This commit is contained in:
35
taskfile/read/node.go
Normal file
35
taskfile/read/node.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package read
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-task/task/v3/taskfile"
|
||||
)
|
||||
|
||||
type Node interface {
|
||||
Read() (*taskfile.Taskfile, error)
|
||||
Parent() Node
|
||||
Optional() bool
|
||||
Location() string
|
||||
}
|
||||
|
||||
func NewNodeFromIncludedTaskfile(parent Node, includedTaskfile taskfile.IncludedTaskfile) (Node, error) {
|
||||
switch getScheme(includedTaskfile.Taskfile) {
|
||||
// TODO: Add support for other schemes.
|
||||
// If no other scheme matches, we assume it's a file.
|
||||
// This also allows users to explicitly set a file:// scheme.
|
||||
default:
|
||||
path, err := includedTaskfile.FullTaskfilePath()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewFileNode(parent, path, includedTaskfile.Optional)
|
||||
}
|
||||
}
|
||||
|
||||
func getScheme(uri string) string {
|
||||
if i := strings.Index(uri, "://"); i != -1 {
|
||||
return uri[:i]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user