1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00
task/precondition.go
Pete Davison 247c2586c2
refactor: taskfile/ast package (#1450)
* refactor: ast package

* feat: read -> taskfile

* refactor: taskfile.Taskfile -> taskfile.Read

* refactor: move merge function back into taskfile package

* refactor: rename taskfile.go to read.go
2023-12-29 20:32:03 +00:00

33 lines
804 B
Go

package task
import (
"context"
"errors"
"github.com/go-task/task/v3/internal/env"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/taskfile/ast"
)
// ErrPreconditionFailed is returned when a precondition fails
var ErrPreconditionFailed = errors.New("task: precondition not met")
func (e *Executor) areTaskPreconditionsMet(ctx context.Context, t *ast.Task) (bool, error) {
for _, p := range t.Preconditions {
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
Command: p.Sh,
Dir: t.Dir,
Env: env.Get(t),
})
if err != nil {
if !errors.Is(err, context.Canceled) {
e.Logger.Errf(logger.Magenta, "task: %s\n", p.Msg)
}
return false, ErrPreconditionFailed
}
}
return true, nil
}