refactor: merge Setup into NewExecutor

This commit is contained in:
Pete Davison
2025-02-24 09:52:12 +00:00
parent 4b99f60039
commit 1402e2baaf
3 changed files with 12 additions and 10 deletions

View File

@@ -152,17 +152,12 @@ func run() error {
return err
}
tf, err := graph.Merge()
if err != nil {
return err
}
executor := task.NewExecutor(tf,
executor, err := task.NewExecutor(graph,
flags.WithFlags(),
task.WithDir(node.Dir()),
task.WithTempDir(tempDir),
)
if err := executor.Setup(); err != nil {
if err != nil {
return err
}

View File

@@ -71,7 +71,11 @@ type (
// NewExecutor creates a new [Executor] and applies the given functional options
// to it.
func NewExecutor(tf *ast.Taskfile, opts ...ExecutorOption) *Executor {
func NewExecutor(graph *ast.TaskfileGraph, opts ...ExecutorOption) (*Executor, error) {
tf, err := graph.Merge()
if err != nil {
return nil, err
}
e := &Executor{
Taskfile: tf,
Stdin: os.Stdin,
@@ -91,7 +95,10 @@ func NewExecutor(tf *ast.Taskfile, opts ...ExecutorOption) *Executor {
executionHashesMutex: sync.Mutex{},
}
e.Options(opts...)
return e
if err := e.setup(); err != nil {
return nil, err
}
return e, nil
}
// Options loops through the given [ExecutorOption] functions and applies them

View File

@@ -18,7 +18,7 @@ import (
"github.com/go-task/task/v3/taskfile/ast"
)
func (e *Executor) Setup() error {
func (e *Executor) setup() error {
e.setupLogger()
e.setupFuzzyModel()
e.setupStdFiles()