1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00
task/requires.go
2024-09-09 16:05:47 +00:00

34 lines
656 B
Go

package task
import (
"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/taskfile/ast"
)
func (e *Executor) areTaskRequiredVarsSet(t *ast.Task, call *ast.Call) error {
if t.Requires == nil || len(t.Requires.Vars) == 0 {
return nil
}
vars, err := e.Compiler.GetVariables(t, call)
if err != nil {
return err
}
var missingVars []string
for _, requiredVar := range t.Requires.Vars {
if _, ok := vars.Get(requiredVar); !ok {
missingVars = append(missingVars, requiredVar)
}
}
if len(missingVars) > 0 {
return &errors.TaskMissingRequiredVars{
TaskName: t.Name(),
MissingVars: missingVars,
}
}
return nil
}