1
0
mirror of https://github.com/go-task/task.git synced 2025-01-26 05:27:15 +02:00

display summary for tasks without summary/description

This commit is contained in:
jaedle 2019-02-24 19:02:44 +01:00
parent 3f8ee21849
commit 3ca590b185
6 changed files with 22 additions and 61 deletions

View File

@ -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

12
task.go
View File

@ -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

View File

@ -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 {

View File

@ -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'

View File

@ -1,8 +0,0 @@
task: task-with-summary-containing-empty-line
First line followed by empty line
Last Line
commands:
- exit 0

View File

@ -1,6 +0,0 @@
task: task-without-commands
summary
dependencies:
- dependend-task-1