1
0
mirror of https://github.com/go-task/task.git synced 2025-11-25 22:32:55 +02:00

feat: root remote taskfiles

This commit is contained in:
Pete Davison
2024-02-13 01:07:00 +00:00
parent f00693052a
commit cbc19d35ea
12 changed files with 261 additions and 132 deletions

View File

@@ -5,19 +5,23 @@ import (
"context"
"fmt"
"os"
"strings"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/taskfile/ast"
)
// A StdinNode is a node that reads a taskfile from the standard input stream.
type StdinNode struct {
*BaseNode
Dir string
}
func NewStdinNode(dir string) (*StdinNode, error) {
base := NewBaseNode()
base.dir = dir
return &StdinNode{
BaseNode: base,
Dir: dir,
}, nil
}
@@ -41,6 +45,33 @@ func (node *StdinNode) Read(ctx context.Context) ([]byte, error) {
return stdin, nil
}
func (node *StdinNode) BaseDir() string {
return node.Dir
func (node *StdinNode) ResolveIncludeEntrypoint(include ast.Include) (string, error) {
// If the file is remote, we don't need to resolve the path
if strings.Contains(include.Taskfile, "://") {
return include.Taskfile, nil
}
path, err := execext.Expand(include.Taskfile)
if err != nil {
return "", err
}
if filepathext.IsAbs(path) {
return path, nil
}
return filepathext.SmartJoin(node.Dir(), path), nil
}
func (node *StdinNode) ResolveIncludeDir(include ast.Include) (string, error) {
path, err := execext.Expand(include.Dir)
if err != nil {
return "", err
}
if filepathext.IsAbs(path) {
return path, nil
}
return filepathext.SmartJoin(node.Dir(), path), nil
}