1
0
mirror of https://github.com/go-task/task.git synced 2024-12-14 10:52:43 +02:00
task/precondition.go

32 lines
669 B
Go
Raw Normal View History

2019-05-17 22:13:47 +02:00
package task
import (
"context"
"errors"
"github.com/go-task/task/v2/internal/execext"
"github.com/go-task/task/v2/internal/taskfile"
)
var (
2019-05-28 22:02:59 +02:00
// ErrPreconditionFailed is returned when a precondition fails
ErrPreconditionFailed = errors.New("task: precondition not met")
2019-05-17 22:13:47 +02:00
)
func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *taskfile.Task) (bool, error) {
2019-05-28 22:02:59 +02:00
for _, p := range t.Preconditions {
2019-05-17 22:13:47 +02:00
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: p.Sh,
Dir: t.Dir,
Env: getEnviron(t),
})
if err != nil {
2019-06-11 21:20:56 +02:00
e.Logger.Errf("task: %s", p.Msg)
2019-05-28 22:02:59 +02:00
return false, ErrPreconditionFailed
2019-05-17 22:13:47 +02:00
}
}
return true, nil
}