1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00
task/hash.go

26 lines
437 B
Go
Raw Normal View History

2020-08-17 21:25:17 +02:00
package task
import (
"cmp"
2020-08-17 21:25:17 +02:00
"fmt"
"github.com/go-task/task/v3/internal/hash"
"github.com/go-task/task/v3/taskfile/ast"
2020-08-17 21:25:17 +02:00
)
func (e *Executor) GetHash(t *ast.Task) (string, error) {
r := cmp.Or(t.Run, e.Taskfile.Run)
2020-08-17 21:25:17 +02:00
var h hash.HashFunc
switch r {
case "always":
h = hash.Empty
case "once":
h = hash.Name
case "when_changed":
h = hash.Hash
default:
return "", fmt.Errorf(`task: invalid run "%s"`, r)
}
return h(t)
}