Skip to content

Commit 7e0346d

Browse files
committed
Add CHANGELOG, documentation and small improvements to #401
1 parent 00a90d1 commit 7e0346d

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
## Unreleased
44

5+
- A new `--list-all` (alias `-a`) flag is now available. It's similar to the
6+
exiting `--list` (`-l`) but prints all tasks, even those without a
7+
description
8+
([#383](https://github.com/go-task/task/issues/383), [#401](https://github.com/go-task/task/pull/401)).
59
- It's now possible to schedule cleanup commands to run once a task finishes
610
with the `defer:` keyword
7-
([Documentation](https://taskfile.dev/#/usage?id=doing-task-cleanup-with-defer), [#475](https://github.com/go-task/task/issues/475), [#626](https://github.com/go-task/task/pull/626/files)).
11+
([Documentation](https://taskfile.dev/#/usage?id=doing-task-cleanup-with-defer), [#475](https://github.com/go-task/task/issues/475), [#626](https://github.com/go-task/task/pull/626)).
812
- Remove long deprecated and undocumented `$` variable prefix and `^` command
913
prefix
1014
([#642](https://github.com/go-task/task/issues/642), [#644](https://github.com/go-task/task/issues/644), [#645](https://github.com/go-task/task/pull/645)).

cmd/task/task.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func main() {
8080
pflag.BoolVarP(&helpFlag, "help", "h", false, "shows Task usage")
8181
pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yaml in the current folder")
8282
pflag.BoolVarP(&list, "list", "l", false, "lists tasks with description of current Taskfile")
83-
pflag.BoolVarP(&listAll, "list-all", "a", false, "list tasks with or without a description")
83+
pflag.BoolVarP(&listAll, "list-all", "a", false, "lists tasks with or without a description")
8484
pflag.BoolVar(&status, "status", false, "exits with non-zero exit code if any of the given tasks is not up-to-date")
8585
pflag.BoolVarP(&force, "force", "f", false, "forces execution even when the task is up-to-date")
8686
pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task")
@@ -156,6 +156,7 @@ func main() {
156156

157157
if list {
158158
e.ListTasksWithDesc()
159+
return
159160
}
160161

161162
if listAll {

docs/usage.md

+2
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ would print the following output:
742742
* test: Run all the go tests.
743743
```
744744

745+
If you want to see all tasks, there's a `--list-all` (alias `-a`) flag as well.
746+
745747
## Display summary of task
746748

747749
Running `task --summary task-name` will show a summary of a task.

help.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,32 @@ import (
99
"github.com/go-task/task/v3/taskfile"
1010
)
1111

12-
// PrintTasksHelp prints tasks' help.
13-
// Behavior is governed by listAll. When false, only tasks with descriptions are reported.
14-
// When true, all tasks are reported with descriptions shown where available.
15-
func (e *Executor) PrintTasksHelp(listAll bool) {
12+
// ListTasksWithDesc reports tasks that have a description spec.
13+
func (e *Executor) ListTasksWithDesc() {
14+
e.pringTasks(false)
15+
return
16+
}
17+
18+
// ListAllTasks reports all tasks, with or without a description spec.
19+
func (e *Executor) ListAllTasks() {
20+
e.pringTasks(true)
21+
return
22+
}
23+
24+
func (e *Executor) pringTasks(listAll bool) {
1625
var tasks []*taskfile.Task
17-
if listAll == true {
26+
if listAll {
1827
tasks = e.allTaskNames()
1928
} else {
2029
tasks = e.tasksWithDesc()
2130
}
2231

2332
if len(tasks) == 0 {
24-
// TODO: This message should be more informative. Maybe a hint to try -la for showing all?
25-
e.Logger.Outf(logger.Yellow, "task: No tasks with description available")
33+
if listAll {
34+
e.Logger.Outf(logger.Yellow, "task: No tasks available")
35+
} else {
36+
e.Logger.Outf(logger.Yellow, "task: No tasks with description available. Try --list-all to list all tasks")
37+
}
2638
return
2739
}
2840
e.Logger.Outf(logger.Default, "task: Available tasks for this project:")
@@ -58,15 +70,3 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
5870
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
5971
return
6072
}
61-
62-
// ListTasksWithDesc reports tasks that have a description spec.
63-
func (e *Executor) ListTasksWithDesc() {
64-
e.PrintTasksHelp(false)
65-
return
66-
}
67-
68-
// ListAllTasks reports all tasks, with or without a description spec.
69-
func (e *Executor) ListAllTasks() {
70-
e.PrintTasksHelp(true)
71-
return
72-
}

task_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func TestLabelInList(t *testing.T) {
518518
Stderr: &buff,
519519
}
520520
assert.NoError(t, e.Setup())
521-
e.PrintTasksHelp(false)
521+
e.ListTasksWithDesc()
522522
assert.Contains(t, buff.String(), "foobar")
523523
}
524524

0 commit comments

Comments
 (0)