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:
parent
3f8ee21849
commit
3ca590b185
@ -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
12
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
|
||||
|
14
task_test.go
14
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 {
|
||||
|
17
testdata/summary/Taskfile.yml
vendored
17
testdata/summary/Taskfile.yml
vendored
@ -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'
|
||||
|
@ -1,8 +0,0 @@
|
||||
task: task-with-summary-containing-empty-line
|
||||
|
||||
First line followed by empty line
|
||||
|
||||
Last Line
|
||||
|
||||
commands:
|
||||
- exit 0
|
6
testdata/summary/task-without-commands.txt
vendored
6
testdata/summary/task-without-commands.txt
vendored
@ -1,6 +0,0 @@
|
||||
task: task-without-commands
|
||||
|
||||
summary
|
||||
|
||||
dependencies:
|
||||
- dependend-task-1
|
Loading…
x
Reference in New Issue
Block a user