From dd55023397398a779bc193bbaca9c8971783ab57 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Nov 2022 21:20:20 -0700 Subject: [PATCH] fix: log the checked files if verbose --- internal/status/checksum.go | 2 +- internal/status/glob.go | 2 +- internal/status/timestamp.go | 6 +++--- status.go | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/internal/status/checksum.go b/internal/status/checksum.go index 6a03e14791..7f835b92e8 100644 --- a/internal/status/checksum.go +++ b/internal/status/checksum.go @@ -34,7 +34,7 @@ func (c *Checksum) IsUpToDate() (bool, error) { data, _ := os.ReadFile(checksumFile) oldMd5 := strings.TrimSpace(string(data)) - sources, err := globs(c.TaskDir, c.Sources) + sources, err := Globs(c.TaskDir, c.Sources) if err != nil { return false, err } diff --git a/internal/status/glob.go b/internal/status/glob.go index d04214bebf..755f8328fe 100644 --- a/internal/status/glob.go +++ b/internal/status/glob.go @@ -10,7 +10,7 @@ import ( "github.com/go-task/task/v3/internal/filepathext" ) -func globs(dir string, globs []string) ([]string, error) { +func Globs(dir string, globs []string) ([]string, error) { files := make([]string, 0) for _, g := range globs { f, err := Glob(dir, g) diff --git a/internal/status/timestamp.go b/internal/status/timestamp.go index 3801c1acb3..69f18192d7 100644 --- a/internal/status/timestamp.go +++ b/internal/status/timestamp.go @@ -19,11 +19,11 @@ func (t *Timestamp) IsUpToDate() (bool, error) { return false, nil } - sources, err := globs(t.Dir, t.Sources) + sources, err := Globs(t.Dir, t.Sources) if err != nil { return false, nil } - generates, err := globs(t.Dir, t.Generates) + generates, err := Globs(t.Dir, t.Generates) if err != nil { return false, nil } @@ -47,7 +47,7 @@ func (t *Timestamp) Kind() string { // Value implements the Checker Interface func (t *Timestamp) Value() (interface{}, error) { - sources, err := globs(t.Dir, t.Sources) + sources, err := Globs(t.Dir, t.Sources) if err != nil { return time.Now(), err } diff --git a/status.go b/status.go index 4d8a120e2f..361af49871 100644 --- a/status.go +++ b/status.go @@ -3,6 +3,7 @@ package task import ( "context" "fmt" + "strings" "github.com/go-task/task/v3/internal/execext" "github.com/go-task/task/v3/internal/logger" @@ -48,6 +49,9 @@ func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, if err != nil { return false, err } + + logInputsGenerates(e, t) + isUpToDate, err := checker.IsUpToDate() if err != nil { return false, err @@ -60,6 +64,20 @@ func (e *Executor) isTaskUpToDate(ctx context.Context, t *taskfile.Task) (bool, return true, nil } +// print the sources and generates that are checked if verbose +func logInputsGenerates(e *Executor, t *taskfile.Task) { + if e.Logger.Verbose { + sources, err := status.Globs(t.Dir, t.Sources) + if err == nil { + e.Logger.VerboseOutf(logger.Cyan, "task: sources: [\"%s\"]\n", strings.Join(sources, `", "`)) + } + generates, err := status.Globs(t.Dir, t.Generates) + if err == nil { + e.Logger.VerboseOutf(logger.Cyan, "task: generates: [\"%s\"]\n", strings.Join(generates, `", "`)) + } + } +} + func (e *Executor) statusOnError(t *taskfile.Task) error { checker, err := e.getStatusChecker(t) if err != nil {