mirror of
https://github.com/go-task/task.git
synced 2025-06-23 00:38:19 +02:00
feat: root remote taskfiles
This commit is contained in:
@ -8,20 +8,25 @@ import (
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
"github.com/go-task/task/v3/internal/experiments"
|
||||
"github.com/go-task/task/v3/internal/logger"
|
||||
"github.com/go-task/task/v3/taskfile/ast"
|
||||
)
|
||||
|
||||
type Node interface {
|
||||
Read(ctx context.Context) ([]byte, error)
|
||||
Parent() Node
|
||||
Location() string
|
||||
Dir() string
|
||||
Optional() bool
|
||||
Remote() bool
|
||||
BaseDir() string
|
||||
ResolveIncludeEntrypoint(include ast.Include) (string, error)
|
||||
ResolveIncludeDir(include ast.Include) (string, error)
|
||||
}
|
||||
|
||||
func NewRootNode(
|
||||
dir string,
|
||||
l *logger.Logger,
|
||||
entrypoint string,
|
||||
dir string,
|
||||
insecure bool,
|
||||
) (Node, error) {
|
||||
dir = getDefaultDir(entrypoint, dir)
|
||||
@ -30,32 +35,24 @@ func NewRootNode(
|
||||
if (stat.Mode()&os.ModeCharDevice) == 0 && stat.Size() > 0 {
|
||||
return NewStdinNode(dir)
|
||||
}
|
||||
// If no entrypoint is specified, search for a taskfile
|
||||
if entrypoint == "" {
|
||||
root, err := ExistsWalk(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewNode(root, insecure)
|
||||
}
|
||||
// Use the specified entrypoint
|
||||
uri := filepath.Join(dir, entrypoint)
|
||||
return NewNode(uri, insecure)
|
||||
return NewNode(l, entrypoint, dir, insecure)
|
||||
}
|
||||
|
||||
func NewNode(
|
||||
uri string,
|
||||
l *logger.Logger,
|
||||
entrypoint string,
|
||||
dir string,
|
||||
insecure bool,
|
||||
opts ...NodeOption,
|
||||
) (Node, error) {
|
||||
var node Node
|
||||
var err error
|
||||
switch getScheme(uri) {
|
||||
switch getScheme(entrypoint) {
|
||||
case "http", "https":
|
||||
node, err = NewHTTPNode(uri, insecure, opts...)
|
||||
node, err = NewHTTPNode(l, entrypoint, dir, insecure, opts...)
|
||||
default:
|
||||
// If no other scheme matches, we assume it's a file
|
||||
node, err = NewFileNode(uri, opts...)
|
||||
node, err = NewFileNode(l, entrypoint, dir, opts...)
|
||||
}
|
||||
if node.Remote() && !experiments.RemoteTaskfiles.Enabled {
|
||||
return nil, errors.New("task: Remote taskfiles are not enabled. You can read more about this experiment and how to enable it at https://taskfile.dev/experiments/remote-taskfiles")
|
||||
|
Reference in New Issue
Block a user