Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic when using --list and --silent #1512

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"os"
"strings"
"text/tabwriter"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Loading