Skip to content

Commit 42702e8

Browse files
refactor: wrap PrintTasksHelp with arg-less signatures
provide exported methods for accessing PrintTasksHelp variants.
1 parent 347c796 commit 42702e8

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

cmd/task/task.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ func main() {
150150
return
151151
}
152152

153-
if list || listAll {
154-
e.PrintTasksHelp(listAll)
153+
if list {
154+
e.ListTasksWithDesc()
155+
}
156+
157+
if listAll {
158+
e.ListAllTasks()
155159
return
156160
}
157161

help.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func (e *Executor) PrintTasksHelp(listAll bool) {
1616
var tasks []*taskfile.Task
1717
if listAll == true {
18-
tasks = e.taskNames()
18+
tasks = e.allTaskNames()
1919
} else {
2020
tasks = e.tasksWithDesc()
2121
}
@@ -35,7 +35,7 @@ func (e *Executor) PrintTasksHelp(listAll bool) {
3535
w.Flush()
3636
}
3737

38-
func (e *Executor) taskNames() (tasks []*taskfile.Task) {
38+
func (e *Executor) allTaskNames() (tasks []*taskfile.Task) {
3939
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
4040
for _, task := range e.Taskfile.Tasks {
4141
tasks = append(tasks, task)
@@ -58,3 +58,15 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
5858
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
5959
return
6060
}
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.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
6464
for _, c := range calls {
6565
if _, ok := e.Taskfile.Tasks[c.Task]; !ok {
6666
// FIXME: move to the main package
67-
// FIXME: ([email protected]) changed the PrintTasksHelp signature to support show all/some.
68-
// False preserves original behavior, but should be reviewed.
69-
e.PrintTasksHelp(false)
67+
e.ListTasksWithDesc()
7068
return &taskNotFoundError{taskName: c.Task}
7169
}
7270
}

task_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func TestListAllShowsNoDesc(t *testing.T) {
492492
assert.NoError(t, e.Setup())
493493

494494
var title string
495-
e.PrintTasksHelp(true)
495+
e.ListAllTasks()
496496
for _, title = range []string{
497497
"foo",
498498
"voo",
@@ -514,7 +514,7 @@ func TestListCanListDescOnly(t *testing.T) {
514514
}
515515

516516
assert.NoError(t, e.Setup())
517-
e.PrintTasksHelp(false)
517+
e.ListTasksWithDesc()
518518

519519
var title string
520520
assert.Contains(t, buff.String(), "foo")

0 commit comments

Comments
 (0)