mirror of
https://github.com/go-task/task.git
synced 2025-07-13 01:30:33 +02:00
Merge branch 'list-task-names' of https://github.com/ardnew/task into ardnew-list-task-names
This commit is contained in:
@ -158,6 +158,12 @@ func main() {
|
|||||||
|
|
||||||
OutputStyle: output,
|
OutputStyle: output,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (list || listAll) && silent {
|
||||||
|
e.ListTaskNames(listAll)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := e.Setup(); err != nil {
|
if err := e.Setup(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
30
help.go
30
help.go
@ -2,7 +2,10 @@ package task
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/go-task/task/v3/internal/logger"
|
"github.com/go-task/task/v3/internal/logger"
|
||||||
@ -70,3 +73,30 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
|
|||||||
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
|
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PrintTaskNames 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) {
|
||||||
|
// if called from cmd/task.go, e.Taskfile has not yet been parsed
|
||||||
|
if nil == e.Taskfile && e.readTaskfile() != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// use stdout if no output defined
|
||||||
|
var w io.Writer = os.Stdout
|
||||||
|
if e.Stdout != nil {
|
||||||
|
w = e.Stdout
|
||||||
|
}
|
||||||
|
// create a string slice from all map values (*taskfile.Task)
|
||||||
|
s := make([]string, 0, len(e.Taskfile.Tasks))
|
||||||
|
for _, t := range e.Taskfile.Tasks {
|
||||||
|
if allTasks || t.Desc != "" {
|
||||||
|
s = append(s, strings.TrimRight(t.Task, ":"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// sort and print all task names
|
||||||
|
sort.Strings(s)
|
||||||
|
for _, t := range s {
|
||||||
|
fmt.Fprintln(w, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
15
task.go
15
task.go
@ -104,8 +104,13 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
|
|||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup setups Executor's internal state
|
// readTaskfile selects and parses the entrypoint.
|
||||||
func (e *Executor) Setup() error {
|
func (e *Executor) readTaskfile() error {
|
||||||
|
// select the default entrypoint if not provided
|
||||||
|
if e.Entrypoint == "" {
|
||||||
|
e.Entrypoint = "Taskfile.yml"
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
e.Taskfile, err = read.Taskfile(&read.ReaderNode{
|
e.Taskfile, err = read.Taskfile(&read.ReaderNode{
|
||||||
Dir: e.Dir,
|
Dir: e.Dir,
|
||||||
@ -113,6 +118,12 @@ func (e *Executor) Setup() error {
|
|||||||
Parent: nil,
|
Parent: nil,
|
||||||
Optional: false,
|
Optional: false,
|
||||||
})
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup setups Executor's internal state
|
||||||
|
func (e *Executor) Setup() error {
|
||||||
|
err := e.readTaskfile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user