From 1402e2baaf5696ef4d7f5a67f2dc98711025f701 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Mon, 24 Feb 2025 09:52:12 +0000 Subject: [PATCH] refactor: merge Setup into NewExecutor --- cmd/task/task.go | 9 ++------- executor.go | 11 +++++++++-- setup.go => executor_setup.go | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) rename setup.go => executor_setup.go (99%) diff --git a/cmd/task/task.go b/cmd/task/task.go index b6388b81..24a530a7 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -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 } diff --git a/executor.go b/executor.go index b9560469..ce855c37 100644 --- a/executor.go +++ b/executor.go @@ -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 diff --git a/setup.go b/executor_setup.go similarity index 99% rename from setup.go rename to executor_setup.go index e2bdfc0e..1b8e3465 100644 --- a/setup.go +++ b/executor_setup.go @@ -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()