mirror of
https://github.com/go-task/task.git
synced 2025-04-27 12:32:25 +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
|
## 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:
|
The following Taskfile:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@ -552,23 +552,39 @@ version: '2'
|
|||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
release:
|
release:
|
||||||
details: |
|
deps: [build]
|
||||||
|
summary: |
|
||||||
Release your project to github
|
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 make sure that you have set GITHUB_TOKEN before starting.
|
||||||
cmds:
|
cmds:
|
||||||
- your-release-tool
|
- 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
|
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 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
|
## 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 {
|
if e.Summary {
|
||||||
firstTask := calls[0].Task
|
firstTask := calls[0].Task
|
||||||
e.printTaskSummary(firstTask)
|
summary.Print(e.Logger, e.Taskfile.Tasks[firstTask])
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,16 +82,6 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
|
|||||||
return nil
|
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
|
// Setup setups Executor's internal state
|
||||||
func (e *Executor) Setup() error {
|
func (e *Executor) Setup() error {
|
||||||
var err 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.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary"}))
|
||||||
assert.Equal(t, readTestFixture(t, dir, "task-with-summary.txt"), buff.String())
|
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()
|
buff.Reset()
|
||||||
const firstTask = "other-task-with-summary"
|
const firstTask = "other-task-with-summary"
|
||||||
const secondTask = "task-with-summary"
|
const secondTask = "task-with-summary"
|
||||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: firstTask}, taskfile.Call{Task: secondTask}))
|
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: firstTask}, taskfile.Call{Task: secondTask}))
|
||||||
assert.Contains(t, buff.String(), "summary of "+firstTask)
|
assert.Contains(t, buff.String(), "summary of "+firstTask)
|
||||||
assert.NotContains(t, buff.String(), "summary of "+secondTask)
|
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 {
|
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'
|
- echo 'another command'
|
||||||
- exit 0
|
- exit 0
|
||||||
|
|
||||||
task-without-summary:
|
|
||||||
deps: [dependend-task-1]
|
|
||||||
cmds:
|
|
||||||
- echo 'task-without-summary was executed'
|
|
||||||
|
|
||||||
other-task-with-summary:
|
other-task-with-summary:
|
||||||
summary: summary of other-task-with-summary
|
summary: summary of other-task-with-summary
|
||||||
cmds:
|
cmds:
|
||||||
- echo 'other-task-with-summary was executed'
|
- 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:
|
dependend-task-1:
|
||||||
cmds:
|
cmds:
|
||||||
- echo 'dependend-task-1 was executed'
|
- 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