mirror of
https://github.com/go-task/task.git
synced 2025-03-23 21:29:29 +02:00
Merge pull request #337 from adamwasila/subtask-alias
Allow overriding the task name in the logger output
This commit is contained in:
commit
c6d9201680
2
help.go
2
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()
|
||||
}
|
||||
|
@ -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, "")
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
2
task.go
2
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
|
||||
}
|
||||
|
84
task_test.go
84
task_test.go
@ -384,6 +384,90 @@ func TestStatusChecksum(t *testing.T) {
|
||||
assert.Equal(t, `task: Task "build" is up to date`+"\n", buff.String())
|
||||
}
|
||||
|
||||
func TestLabelUpToDate(t *testing.T) {
|
||||
const dir = "testdata/label_uptodate"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
|
||||
assert.Contains(t, buff.String(), "foobar")
|
||||
}
|
||||
|
||||
func TestLabelSummary(t *testing.T) {
|
||||
const dir = "testdata/label_summary"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Summary: true,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
|
||||
assert.Contains(t, buff.String(), "foobar")
|
||||
}
|
||||
|
||||
func TestLabelInStatus(t *testing.T) {
|
||||
const dir = "testdata/label_status"
|
||||
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
err := e.Status(context.Background(), taskfile.Call{Task: "foo"})
|
||||
if assert.Error(t, err) {
|
||||
assert.Contains(t, err.Error(), "foobar")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelWithVariableExpansion(t *testing.T) {
|
||||
const dir = "testdata/label_var"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
|
||||
assert.Contains(t, buff.String(), "foobaz")
|
||||
}
|
||||
|
||||
func TestLabelInSummary(t *testing.T) {
|
||||
const dir = "testdata/label_summary"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
|
||||
assert.Contains(t, buff.String(), "foobar")
|
||||
}
|
||||
|
||||
func TestLabelInList(t *testing.T) {
|
||||
const dir = "testdata/label_list"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
e.PrintTasksHelp()
|
||||
assert.Contains(t, buff.String(), "foobar")
|
||||
}
|
||||
|
||||
func TestStatusVariables(t *testing.T) {
|
||||
const dir = "testdata/status_vars"
|
||||
|
||||
|
6
testdata/label_list/Taskfile.yml
vendored
Normal file
6
testdata/label_list/Taskfile.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
foo:
|
||||
label: "foobar"
|
||||
desc: "task description"
|
7
testdata/label_status/Taskfile.yml
vendored
Normal file
7
testdata/label_status/Taskfile.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
foo:
|
||||
label: "foobar"
|
||||
status:
|
||||
- "false"
|
8
testdata/label_summary/Taskfile.yml
vendored
Normal file
8
testdata/label_summary/Taskfile.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
foo:
|
||||
label: "foobar"
|
||||
desc: description
|
||||
status:
|
||||
- echo "I'm ok"
|
7
testdata/label_uptodate/Taskfile.yml
vendored
Normal file
7
testdata/label_uptodate/Taskfile.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
foo:
|
||||
label: "foobar"
|
||||
status:
|
||||
- echo "I'm ok"
|
10
testdata/label_var/Taskfile.yml
vendored
Normal file
10
testdata/label_var/Taskfile.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
version: '3'
|
||||
|
||||
vars:
|
||||
BAR: baz
|
||||
|
||||
tasks:
|
||||
foo:
|
||||
label: "foo{{.BAR}}"
|
||||
status:
|
||||
- echo "I'm ok"
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user