From 55847a895e18cb73d811e4fcbb7c63e302539d47 Mon Sep 17 00:00:00 2001 From: Pior Bastida Date: Fri, 11 Jan 2019 23:16:48 -0500 Subject: [PATCH] Move the execution code for a task action in task_runner (#264) --- pkg/tasks/task_action.go | 32 -------------------------------- pkg/tasks/task_runner.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/pkg/tasks/task_action.go b/pkg/tasks/task_action.go index dc1a502c..b7d5bb95 100644 --- a/pkg/tasks/task_action.go +++ b/pkg/tasks/task_action.go @@ -25,35 +25,3 @@ func actionNeeded(message string, args ...interface{}) *ActionResult { func actionNotNeeded() *ActionResult { return &ActionResult{Needed: false} } - -func runAction(ctx *Context, action TaskAction) error { - desc := action.Description() - - result := action.Needed(ctx) - if result.Error != nil { - return fmt.Errorf("The task action (%s) failed to detect whether it need to run: %s", desc, result.Error) - } - - if result.Needed { - if desc != "" { - ctx.ui.TaskActionHeader(desc) - } - ctx.ui.Debug("Reason: \"%s\"", result.Reason) - - err := action.Run(ctx) - if err != nil { - return fmt.Errorf("The task action failed to run: %s", err) - } - - result = action.Needed(ctx) - if result.Error != nil { - return fmt.Errorf("The task action failed to detect if it is resolved: %s", result.Error) - } - - if result.Needed { - return fmt.Errorf("The task action did not produce the expected result: %s", result.Reason) - } - } - - return nil -} diff --git a/pkg/tasks/task_runner.go b/pkg/tasks/task_runner.go index 7f22b367..2c895d01 100644 --- a/pkg/tasks/task_runner.go +++ b/pkg/tasks/task_runner.go @@ -84,3 +84,35 @@ func (r *TaskRunnerImpl) activateFeature(ctx *Context, task *Task) error { // itself with the PATH value from the specified Env. return os.Setenv("PATH", ctx.env.Get("PATH")) } + +func runAction(ctx *Context, action TaskAction) error { + desc := action.Description() + + result := action.Needed(ctx) + if result.Error != nil { + return fmt.Errorf("The task action (%s) failed to detect whether it need to run: %s", desc, result.Error) + } + + if result.Needed { + if desc != "" { + ctx.ui.TaskActionHeader(desc) + } + ctx.ui.Debug("Reason: \"%s\"", result.Reason) + + err := action.Run(ctx) + if err != nil { + return fmt.Errorf("The task action failed to run: %s", err) + } + + result = action.Needed(ctx) + if result.Error != nil { + return fmt.Errorf("The task action failed to detect if it is resolved: %s", result.Error) + } + + if result.Needed { + return fmt.Errorf("The task action did not produce the expected result: %s", result.Reason) + } + } + + return nil +}