From 9f83311931ba263eaffccefea775a71d1163156d Mon Sep 17 00:00:00 2001 From: Adam Wasila Date: Wed, 3 Jun 2020 22:19:12 +0200 Subject: [PATCH] Add label field to task definition Label is an alternative name for task that replace it when printed in following context eg.: - log: when given task is up to date and is skipped from execution - log: when given task is NOT up to date (`--status` command) - in `--summary` and `--list` commands output --- help.go | 2 +- internal/summary/summary.go | 2 +- internal/taskfile/task.go | 10 ++++++++++ status.go | 2 +- task.go | 2 +- variables.go | 1 + 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/help.go b/help.go index cfd6a109..0867ca5f 100644 --- a/help.go +++ b/help.go @@ -21,7 +21,7 @@ func (e *Executor) PrintTasksHelp() { // Format in tab-separated columns with a tab stop of 8. w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0) for _, task := range tasks { - fmt.Fprintf(w, "* %s: \t%s\n", task.Task, task.Desc) + fmt.Fprintf(w, "* %s: \t%s\n", task.Name(), task.Desc) } w.Flush() } diff --git a/internal/summary/summary.go b/internal/summary/summary.go index ea932187..baa4f481 100644 --- a/internal/summary/summary.go +++ b/internal/summary/summary.go @@ -56,7 +56,7 @@ func printTaskSummary(l *logger.Logger, t *taskfile.Task) { } func printTaskName(l *logger.Logger, t *taskfile.Task) { - l.Outf(logger.Default, "task: %s", t.Task) + l.Outf(logger.Default, "task: %s", t.Name()) l.Outf(logger.Default, "") } diff --git a/internal/taskfile/task.go b/internal/taskfile/task.go index d39999cf..40c66b58 100644 --- a/internal/taskfile/task.go +++ b/internal/taskfile/task.go @@ -12,6 +12,7 @@ type Task struct { Task string Cmds []*Cmd Deps []*Dep + Label string Desc string Summary string Sources []string @@ -32,6 +33,13 @@ var ( ErrCantUnmarshalTask = errors.New("task: can't unmarshal task value") ) +func (t *Task) Name() string { + if t.Label != "" { + return t.Label + } + return t.Task +} + func (t *Task) UnmarshalYAML(unmarshal func(interface{}) error) error { var cmd Cmd if err := unmarshal(&cmd); err == nil && cmd.Cmd != "" { @@ -48,6 +56,7 @@ func (t *Task) UnmarshalYAML(unmarshal func(interface{}) error) error { var task struct { Cmds []*Cmd Deps []*Dep + Label string Desc string Summary string Sources []string @@ -65,6 +74,7 @@ func (t *Task) UnmarshalYAML(unmarshal func(interface{}) error) error { if err := unmarshal(&task); err == nil { t.Cmds = task.Cmds t.Deps = task.Deps + t.Label = task.Label t.Desc = task.Desc t.Summary = task.Summary t.Sources = task.Sources diff --git a/status.go b/status.go index 5421c1ca..83f383e6 100644 --- a/status.go +++ b/status.go @@ -22,7 +22,7 @@ func (e *Executor) Status(ctx context.Context, calls ...taskfile.Call) error { return err } if !isUpToDate { - return fmt.Errorf(`task: Task "%s" is not up-to-date`, t.Task) + return fmt.Errorf(`task: Task "%s" is not up-to-date`, t.Name()) } } return nil diff --git a/task.go b/task.go index f5439138..2807dd7f 100644 --- a/task.go +++ b/task.go @@ -272,7 +272,7 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error { if upToDate && preCondMet { if !e.Silent { - e.Logger.Errf(logger.Magenta, `task: Task "%s" is up to date`, t.Task) + e.Logger.Errf(logger.Magenta, `task: Task "%s" is up to date`, t.Name()) } return nil } diff --git a/variables.go b/variables.go index dfab8764..4470d296 100644 --- a/variables.go +++ b/variables.go @@ -32,6 +32,7 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) { new := taskfile.Task{ Task: origTask.Task, + Label: r.Replace(origTask.Label), Desc: r.Replace(origTask.Desc), Summary: r.Replace(origTask.Summary), Sources: r.ReplaceSlice(origTask.Sources),