From 07a0b8938f4f0c56de4c10ed23371ccb07f27339 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Mon, 19 Feb 2024 21:15:51 +0000 Subject: [PATCH] refactor: bubble errors from ListTaskNames --- cmd/task/task.go | 3 +-- help.go | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cmd/task/task.go b/cmd/task/task.go index f3144703..e9284427 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -265,8 +265,7 @@ func run() error { } if (listOptions.ShouldListTasks()) && flags.silent { - e.ListTaskNames(flags.listAll) - return nil + return e.ListTaskNames(flags.listAll) } if err := e.Setup(); err != nil { diff --git a/help.go b/help.go index baea689e..afb16e53 100644 --- a/help.go +++ b/help.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "log" "os" "strings" "text/tabwriter" @@ -121,7 +120,7 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) { // ListTaskNames prints only the task names in a Taskfile. // Only tasks with a non-empty description are printed if allTasks is false. // Otherwise, all task names are printed. -func (e *Executor) ListTaskNames(allTasks bool) { +func (e *Executor) ListTaskNames(allTasks bool) error { // if called from cmd/task.go, e.Logger has not yet been initialized if e.Logger == nil { e.setupLogger() @@ -129,8 +128,7 @@ func (e *Executor) ListTaskNames(allTasks bool) { // if called from cmd/task.go, e.Taskfile has not yet been parsed if e.Taskfile == nil { if err := e.readTaskfile(); err != nil { - log.Fatal(err) - return + return err } } // use stdout if no output defined @@ -161,6 +159,7 @@ func (e *Executor) ListTaskNames(allTasks bool) { for _, t := range taskNames { fmt.Fprintln(w, t) } + return nil } func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Taskfile, error) {