Skip to content

Commit

Permalink
Move the execution code for a task action in task_runner (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
pior committed Jan 12, 2019
1 parent 6973f00 commit 55847a8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 0 additions & 32 deletions pkg/tasks/task_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
32 changes: 32 additions & 0 deletions pkg/tasks/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 55847a8

Please sign in to comment.