1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

print commands on summary only if commands are present

This commit is contained in:
jaedle
2019-02-24 16:08:32 +01:00
parent 31ecf167cc
commit 4dcb124693
3 changed files with 16 additions and 18 deletions

11
task.go
View File

@@ -98,9 +98,13 @@ func (e *Executor) printTaskSummary(task string) {
} }
func printCommands(cmds []*taskfile.Cmd, logger *logger.Logger) { func printCommands(cmds []*taskfile.Cmd, logger *logger.Logger) {
logger.Outf("commands:") hasCommands := len(cmds) > 0
for _, c := range cmds { if hasCommands {
logger.Outf(" - %s", c.Cmd) logger.Outf("")
logger.Outf("commands:")
for _, c := range cmds {
logger.Outf(" - %s", c.Cmd)
}
} }
} }
@@ -114,7 +118,6 @@ func printTaskDependencies(deps []*taskfile.Dep, logger *logger.Logger) {
logger.Outf(" - %s", d.Task) logger.Outf(" - %s", d.Task)
} }
} }
logger.Outf("")
} }
func printTaskSummary(description string, Logger *logger.Logger) { func printTaskSummary(description string, Logger *logger.Logger) {

View File

@@ -554,19 +554,6 @@ func TestIncludesCallingRoot(t *testing.T) {
tt.Run(t) tt.Run(t)
} }
func TestSummaryParsing(t *testing.T) {
const dir = "testdata/summary"
e := task.Executor{
Dir: dir,
}
assert.NoError(t, e.Setup())
assert.Equal(t, e.Taskfile.Tasks["task-with-summary"].Summary, "summary of task-with-summary - line 1\nline 2\nline 3\n")
assert.Equal(t, e.Taskfile.Tasks["other-task-with-summary"].Summary, "summary of other-task-with-summary")
assert.Equal(t, e.Taskfile.Tasks["task-without-summary"].Summary, "")
}
func TestSummary(t *testing.T) { func TestSummary(t *testing.T) {
const dir = "testdata/summary" const dir = "testdata/summary"
@@ -598,6 +585,10 @@ func TestSummary(t *testing.T) {
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary-containing-empty-line"})) assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary-containing-empty-line"}))
assert.Equal(t, readTestFixture(t, dir, "task-with-summary-containing-empty-line.txt"), buff.String()) assert.Equal(t, readTestFixture(t, dir, "task-with-summary-containing-empty-line.txt"), buff.String())
buff.Reset()
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-without-commands"}))
assert.Equal(t, readTestFixture(t, dir, "task-without-commands.txt"), buff.String())
} }
func readTestFixture(t *testing.T, dir string, file string) string { func readTestFixture(t *testing.T, dir string, file string) string {

View File

@@ -12,7 +12,7 @@ tasks:
- exit 0 - exit 0
task-without-summary: task-without-summary:
deps: [dependend-task] deps: [dependend-task-1]
cmds: cmds:
- echo 'task-without-summary was executed' - echo 'task-without-summary was executed'
@@ -36,3 +36,7 @@ tasks:
Last Line Last Line
cmds: cmds:
- exit 0 - exit 0
task-without-commands:
summary: summary
deps: [dependend-task-1]