mirror of
https://github.com/go-task/task.git
synced 2024-12-12 10:45:49 +02:00
9bed7f7a9b
added an add'l cli option that lists all tasks, with or without description. orig. behavior: task -l lists tasks with desc field new behaviour: task -la or task -a will list all tasks. if task has desc, it will be included. BREAKING CHANGES: none, that I know of. NOTES/Concerns: - This is wip. - Haven't checked how it interacts with bash completion. - The new Executor.TaskNames func does not use e.CompiledTask(taskfile.Call{Task: task.Task})
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package task
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"text/tabwriter"
|
|
|
|
"github.com/go-task/task/v3/internal/logger"
|
|
"github.com/go-task/task/v3/taskfile"
|
|
)
|
|
|
|
// PrintTasksHelp prints tasks' help.
|
|
// Behavior is governed by listAll. When false, only tasks with descriptions are reported.
|
|
// When true, all tasks are reported with descriptions shown where available.
|
|
func (e *Executor) PrintTasksHelp(listAll bool) {
|
|
var tasks []*taskfile.Task
|
|
if listAll == true {
|
|
tasks = e.taskNames()
|
|
} else {
|
|
tasks = e.tasksWithDesc()
|
|
}
|
|
|
|
if len(tasks) == 0 {
|
|
// TODO: This message should be more informative. Maybe a hint to try -la for showing all?
|
|
e.Logger.Outf(logger.Yellow, "task: No tasks with description available")
|
|
return
|
|
}
|
|
e.Logger.Outf(logger.Default, "task: Available tasks for this project:")
|
|
|
|
// Format in tab-separated columns with a tab stop of 8.
|
|
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
|
|
for _, task := range tasks {
|
|
fmt.Fprintf(w, "* %s: \t%s\n", task.Name(), task.Desc)
|
|
}
|
|
w.Flush()
|
|
}
|
|
|
|
func (e *Executor) taskNames() (tasks []*taskfile.Task) {
|
|
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
|
for _, task := range e.Taskfile.Tasks {
|
|
tasks = append(tasks, task)
|
|
}
|
|
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
|
|
return
|
|
}
|
|
|
|
func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
|
|
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
|
for _, task := range e.Taskfile.Tasks {
|
|
if task.Desc != "" {
|
|
compiledTask, err := e.CompiledTask(taskfile.Call{Task: task.Task})
|
|
if err == nil {
|
|
task = compiledTask
|
|
}
|
|
tasks = append(tasks, task)
|
|
}
|
|
}
|
|
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
|
|
return
|
|
}
|