1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

Merge branch 'f/list-all' of https://github.com/therealkevinard/task into therealkevinard-f/list-all

This commit is contained in:
Andrey Nering
2022-01-04 17:03:12 -03:00
5 changed files with 102 additions and 6 deletions

36
help.go
View File

@@ -9,10 +9,19 @@ import (
"github.com/go-task/task/v3/taskfile"
)
// PrintTasksHelp prints help os tasks that have a description
func (e *Executor) PrintTasksHelp() {
tasks := e.tasksWithDesc()
// 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.allTaskNames()
} 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
}
@@ -26,6 +35,15 @@ func (e *Executor) PrintTasksHelp() {
w.Flush()
}
func (e *Executor) allTaskNames() (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 {
@@ -40,3 +58,15 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
return
}
// ListTasksWithDesc reports tasks that have a description spec.
func (e *Executor) ListTasksWithDesc() {
e.PrintTasksHelp(false)
return
}
// ListAllTasks reports all tasks, with or without a description spec.
func (e *Executor) ListAllTasks() {
e.PrintTasksHelp(true)
return
}