mirror of
https://github.com/go-task/task.git
synced 2025-01-10 04:18:53 +02:00
37 lines
887 B
Go
37 lines
887 B
Go
|
package fingerprint
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"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"
|
||
|
)
|
||
|
|
||
|
type StatusChecker struct {
|
||
|
logger *logger.Logger
|
||
|
}
|
||
|
|
||
|
func NewStatusChecker(logger *logger.Logger) StatusCheckable {
|
||
|
return &StatusChecker{
|
||
|
logger: logger,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (checker *StatusChecker) IsUpToDate(ctx context.Context, t *taskfile.Task) (bool, error) {
|
||
|
for _, s := range t.Status {
|
||
|
err := execext.RunCommand(ctx, &execext.RunCommandOptions{
|
||
|
Command: s,
|
||
|
Dir: t.Dir,
|
||
|
Env: env.Get(t),
|
||
|
})
|
||
|
if err != nil {
|
||
|
checker.logger.VerboseOutf(logger.Yellow, "task: status command %s exited non-zero: %s", s, err)
|
||
|
return false, nil
|
||
|
}
|
||
|
checker.logger.VerboseOutf(logger.Yellow, "task: status command %s exited zero", s)
|
||
|
}
|
||
|
return true, nil
|
||
|
}
|