Files
task/taskfile/node_stdin.go
cui fliter d2b02e3c69 fix: preserve stdin taskfile bytes (#2950)
Signed-off-by: cuishuang <imcusg@gmail.com>
2026-08-09 18:55:17 +00:00

64 lines
1.2 KiB
Go

package taskfile
import (
"io"
"os"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/filepathext"
)
// A StdinNode is a node that reads a taskfile from the standard input stream.
type StdinNode struct {
*baseNode
}
func NewStdinNode(dir string) (*StdinNode, error) {
return &StdinNode{
baseNode: NewBaseNode(dir),
}, nil
}
func (node *StdinNode) Location() string {
return "__stdin__"
}
func (node *StdinNode) Remote() bool {
return false
}
func (node *StdinNode) Read() ([]byte, error) {
return io.ReadAll(os.Stdin)
}
func (node *StdinNode) ResolveEntrypoint(entrypoint string) (string, error) {
// If the file is remote, we don't need to resolve the path
if IsRemoteEntrypoint(entrypoint) {
return entrypoint, nil
}
path, err := execext.ExpandLiteral(entrypoint)
if err != nil {
return "", err
}
if filepathext.IsAbs(path) {
return path, nil
}
return filepathext.SmartJoin(node.Dir(), path), nil
}
func (node *StdinNode) ResolveDir(dir string) (string, error) {
path, err := execext.ExpandLiteral(dir)
if err != nil {
return "", err
}
if filepathext.IsAbs(path) {
return path, nil
}
return filepathext.SmartJoin(node.Dir(), path), nil
}