mirror of
https://github.com/go-task/task.git
synced 2025-12-01 22:52:02 +02:00
feat: stdin node
This commit is contained in:
@@ -2,6 +2,8 @@ package taskfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/go-task/task/v3/errors"
|
||||
@@ -16,6 +18,29 @@ type Node interface {
|
||||
Remote() bool
|
||||
}
|
||||
|
||||
func NewRootNode(
|
||||
dir string,
|
||||
entrypoint string,
|
||||
insecure bool,
|
||||
) (Node, error) {
|
||||
// Check if there is something to read on STDIN
|
||||
stat, _ := os.Stdin.Stat()
|
||||
if (stat.Mode()&os.ModeCharDevice) == 0 && stat.Size() > 0 {
|
||||
return NewStdinNode()
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
|
||||
func NewNode(
|
||||
uri string,
|
||||
insecure bool,
|
||||
|
||||
Reference in New Issue
Block a user