@@ -9,10 +9,19 @@ import (
9
9
"github.com/go-task/task/v3/taskfile"
10
10
)
11
11
12
- // PrintTasksHelp prints help os tasks that have a description
13
- func (e * Executor ) PrintTasksHelp () {
14
- tasks := e .tasksWithDesc ()
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 ) {
16
+ var tasks []* taskfile.Task
17
+ if listAll == true {
18
+ tasks = e .allTaskNames ()
19
+ } else {
20
+ tasks = e .tasksWithDesc ()
21
+ }
22
+
15
23
if len (tasks ) == 0 {
24
+ // TODO: This message should be more informative. Maybe a hint to try -la for showing all?
16
25
e .Logger .Outf (logger .Yellow , "task: No tasks with description available" )
17
26
return
18
27
}
@@ -26,6 +35,15 @@ func (e *Executor) PrintTasksHelp() {
26
35
w .Flush ()
27
36
}
28
37
38
+ func (e * Executor ) allTaskNames () (tasks []* taskfile.Task ) {
39
+ tasks = make ([]* taskfile.Task , 0 , len (e .Taskfile .Tasks ))
40
+ for _ , task := range e .Taskfile .Tasks {
41
+ tasks = append (tasks , task )
42
+ }
43
+ sort .Slice (tasks , func (i , j int ) bool { return tasks [i ].Task < tasks [j ].Task })
44
+ return
45
+ }
46
+
29
47
func (e * Executor ) tasksWithDesc () (tasks []* taskfile.Task ) {
30
48
tasks = make ([]* taskfile.Task , 0 , len (e .Taskfile .Tasks ))
31
49
for _ , task := range e .Taskfile .Tasks {
@@ -40,3 +58,15 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
40
58
sort .Slice (tasks , func (i , j int ) bool { return tasks [i ].Task < tasks [j ].Task })
41
59
return
42
60
}
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
+ }
0 commit comments