diff --git a/cmd/task/task.go b/cmd/task/task.go index f314470317..e92844270a 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 b7f0dfc309..afb16e532c 100644 --- a/help.go +++ b/help.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "log" "os" "strings" "text/tabwriter" @@ -121,12 +120,15 @@ 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() + } // 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 @@ -157,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) {