From 42702e81b35c5b4960c94ff65577f6c4314b0ccd Mon Sep 17 00:00:00 2001 From: Kevin Ard Date: Mon, 3 Jan 2022 12:12:18 -0500 Subject: [PATCH] refactor: wrap PrintTasksHelp with arg-less signatures provide exported methods for accessing PrintTasksHelp variants. --- cmd/task/task.go | 8 ++++++-- help.go | 16 ++++++++++++++-- task.go | 4 +--- task_test.go | 4 ++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/task/task.go b/cmd/task/task.go index 79be2334..05328f42 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -150,8 +150,12 @@ func main() { return } - if list || listAll { - e.PrintTasksHelp(listAll) + if list { + e.ListTasksWithDesc() + } + + if listAll { + e.ListAllTasks() return } diff --git a/help.go b/help.go index f43530e0..8191f147 100644 --- a/help.go +++ b/help.go @@ -15,7 +15,7 @@ import ( func (e *Executor) PrintTasksHelp(listAll bool) { var tasks []*taskfile.Task if listAll == true { - tasks = e.taskNames() + tasks = e.allTaskNames() } else { tasks = e.tasksWithDesc() } @@ -35,7 +35,7 @@ func (e *Executor) PrintTasksHelp(listAll bool) { w.Flush() } -func (e *Executor) taskNames() (tasks []*taskfile.Task) { +func (e *Executor) allTaskNames() (tasks []*taskfile.Task) { tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks)) for _, task := range e.Taskfile.Tasks { tasks = append(tasks, task) @@ -58,3 +58,15 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) { sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task }) return } + +// ListTasksWithDesc reports tasks that have a description spec. +func (e *Executor) ListTasksWithDesc() { + e.PrintTasksHelp(false) + return +} + +// ListAllTasks reports all tasks, with or without a description spec. +func (e *Executor) ListAllTasks() { + e.PrintTasksHelp(true) + return +} diff --git a/task.go b/task.go index d8945be0..ffc573ad 100644 --- a/task.go +++ b/task.go @@ -64,9 +64,7 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error { for _, c := range calls { if _, ok := e.Taskfile.Tasks[c.Task]; !ok { // FIXME: move to the main package - // FIXME: (ard.kevin.84@gmail.com) changed the PrintTasksHelp signature to support show all/some. - // False preserves original behavior, but should be reviewed. - e.PrintTasksHelp(false) + e.ListTasksWithDesc() return &taskNotFoundError{taskName: c.Task} } } diff --git a/task_test.go b/task_test.go index f5ead40c..2d66158e 100644 --- a/task_test.go +++ b/task_test.go @@ -492,7 +492,7 @@ func TestListAllShowsNoDesc(t *testing.T) { assert.NoError(t, e.Setup()) var title string - e.PrintTasksHelp(true) + e.ListAllTasks() for _, title = range []string{ "foo", "voo", @@ -514,7 +514,7 @@ func TestListCanListDescOnly(t *testing.T) { } assert.NoError(t, e.Setup()) - e.PrintTasksHelp(false) + e.ListTasksWithDesc() var title string assert.Contains(t, buff.String(), "foo")