diff --git a/docs/usage.md b/docs/usage.md index 4f6d8aa0..0b1c505a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -544,7 +544,7 @@ would print the following output: ## Detailed task description -Running `task --details task-name` will show a detailed description of a task if present. +Running `task --summary task-name` will show a summary of a task The following Taskfile: ```yaml @@ -552,23 +552,39 @@ version: '2' tasks: release: - details: | + deps: [build] + summary: | Release your project to github + It will build your project before starting the release it. Please make sure that you have set GITHUB_TOKEN before starting. cmds: - your-release-tool + build: + cmds: + - your-build-tool ``` -with running ``task --details release`` would print the following output: +with running ``task --summary release`` would print the following output: ``` +task: release + Release your project to github +It will build your project before starting the release it. Please make sure that you have set GITHUB_TOKEN before starting. -``` -Please note: *showing the detailed description will not execute the command* +dependencies: + - build + +commands: + - your-release-tool +``` +If a summary is missing, the description will be printed. +If the task does not have a summary or a description, a warning is printed. + +Please note: *showing the summary will not execute the command* ## Silent mode diff --git a/task.go b/task.go index b85c8762..2cc84cd7 100644 --- a/task.go +++ b/task.go @@ -66,7 +66,7 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error { if e.Summary { firstTask := calls[0].Task - e.printTaskSummary(firstTask) + summary.Print(e.Logger, e.Taskfile.Tasks[firstTask]) return nil } @@ -82,16 +82,6 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error { return nil } -func (e *Executor) printTaskSummary(task string) { - t := e.Taskfile.Tasks[task] - if t.Summary == "" { - e.Logger.Errf("task: There is no summary for task: %s", task) - return - } - - summary.Print(e.Logger, t) -} - // Setup setups Executor's internal state func (e *Executor) Setup() error { var err error diff --git a/task_test.go b/task_test.go index a3636826..392c40a8 100644 --- a/task_test.go +++ b/task_test.go @@ -569,26 +569,12 @@ func TestSummary(t *testing.T) { assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary"})) assert.Equal(t, readTestFixture(t, dir, "task-with-summary.txt"), buff.String()) - buff.Reset() - const nosummary = "task-without-summary" - assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: nosummary})) - assert.Equal(t, "task: There is no summary for task: "+nosummary+"\n", buff.String()) - buff.Reset() const firstTask = "other-task-with-summary" const secondTask = "task-with-summary" assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: firstTask}, taskfile.Call{Task: secondTask})) assert.Contains(t, buff.String(), "summary of "+firstTask) assert.NotContains(t, buff.String(), "summary of "+secondTask) - - buff.Reset() - 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()) - - 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 { diff --git a/testdata/summary/Taskfile.yml b/testdata/summary/Taskfile.yml index cf07e9df..dc9b6204 100644 --- a/testdata/summary/Taskfile.yml +++ b/testdata/summary/Taskfile.yml @@ -13,28 +13,11 @@ tasks: - echo 'another command' - exit 0 - task-without-summary: - deps: [dependend-task-1] - cmds: - - echo 'task-without-summary was executed' - other-task-with-summary: summary: summary of other-task-with-summary cmds: - echo 'other-task-with-summary was executed' - task-with-summary-containing-empty-line: - summary: | - First line followed by empty line - - Last Line - cmds: - - exit 0 - - task-without-commands: - summary: summary - deps: [dependend-task-1] - dependend-task-1: cmds: - echo 'dependend-task-1 was executed' diff --git a/testdata/summary/task-with-summary-containing-empty-line.txt b/testdata/summary/task-with-summary-containing-empty-line.txt deleted file mode 100644 index 8eca5e86..00000000 --- a/testdata/summary/task-with-summary-containing-empty-line.txt +++ /dev/null @@ -1,8 +0,0 @@ -task: task-with-summary-containing-empty-line - -First line followed by empty line - -Last Line - -commands: - - exit 0 diff --git a/testdata/summary/task-without-commands.txt b/testdata/summary/task-without-commands.txt deleted file mode 100644 index c7c5b024..00000000 --- a/testdata/summary/task-without-commands.txt +++ /dev/null @@ -1,6 +0,0 @@ -task: task-without-commands - -summary - -dependencies: - - dependend-task-1