1
0
mirror of https://github.com/go-task/task.git synced 2025-01-06 03:53:54 +02:00

refactor: bubble errors from ListTaskNames

This commit is contained in:
Pete Davison 2024-02-19 21:15:51 +00:00 committed by Andrey Nering
parent ba81181eb7
commit 07a0b8938f
2 changed files with 4 additions and 6 deletions

View File

@ -265,8 +265,7 @@ func run() error {
} }
if (listOptions.ShouldListTasks()) && flags.silent { if (listOptions.ShouldListTasks()) && flags.silent {
e.ListTaskNames(flags.listAll) return e.ListTaskNames(flags.listAll)
return nil
} }
if err := e.Setup(); err != nil { if err := e.Setup(); err != nil {

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
@ -121,7 +120,7 @@ func (e *Executor) ListTasks(o ListOptions) (bool, error) {
// ListTaskNames prints only the task names in a Taskfile. // ListTaskNames prints only the task names in a Taskfile.
// Only tasks with a non-empty description are printed if allTasks is false. // Only tasks with a non-empty description are printed if allTasks is false.
// Otherwise, all task names are printed. // 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 called from cmd/task.go, e.Logger has not yet been initialized
if e.Logger == nil { if e.Logger == nil {
e.setupLogger() 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 called from cmd/task.go, e.Taskfile has not yet been parsed
if e.Taskfile == nil { if e.Taskfile == nil {
if err := e.readTaskfile(); err != nil { if err := e.readTaskfile(); err != nil {
log.Fatal(err) return err
return
} }
} }
// use stdout if no output defined // use stdout if no output defined
@ -161,6 +159,7 @@ func (e *Executor) ListTaskNames(allTasks bool) {
for _, t := range taskNames { for _, t := range taskNames {
fmt.Fprintln(w, t) fmt.Fprintln(w, t)
} }
return nil
} }
func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Taskfile, error) { func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool) (*editors.Taskfile, error) {