2017-03-19 20:18:18 +02:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"text/tabwriter"
|
2018-02-17 18:22:18 +02:00
|
|
|
|
2020-08-16 20:48:19 +02:00
|
|
|
"github.com/go-task/task/v3/internal/logger"
|
2020-08-19 10:59:58 +02:00
|
|
|
"github.com/go-task/task/v3/taskfile"
|
2017-03-19 20:18:18 +02:00
|
|
|
)
|
|
|
|
|
2017-07-15 19:09:27 +02:00
|
|
|
// PrintTasksHelp prints help os tasks that have a description
|
|
|
|
func (e *Executor) PrintTasksHelp() {
|
2017-06-04 21:02:04 +02:00
|
|
|
tasks := e.tasksWithDesc()
|
2017-03-19 20:18:18 +02:00
|
|
|
if len(tasks) == 0 {
|
2019-05-26 23:36:39 +02:00
|
|
|
e.Logger.Outf(logger.Yellow, "task: No tasks with description available")
|
2017-03-19 20:18:18 +02:00
|
|
|
return
|
|
|
|
}
|
2019-05-26 23:36:39 +02:00
|
|
|
e.Logger.Outf(logger.Default, "task: Available tasks for this project:")
|
2017-03-19 20:18:18 +02:00
|
|
|
|
|
|
|
// Format in tab-separated columns with a tab stop of 8.
|
2017-07-01 20:05:51 +02:00
|
|
|
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
|
2017-03-19 20:18:18 +02:00
|
|
|
for _, task := range tasks {
|
2020-06-03 22:19:12 +02:00
|
|
|
fmt.Fprintf(w, "* %s: \t%s\n", task.Name(), task.Desc)
|
2017-03-19 20:18:18 +02:00
|
|
|
}
|
|
|
|
w.Flush()
|
|
|
|
}
|
|
|
|
|
2018-02-17 18:22:18 +02:00
|
|
|
func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
|
|
|
|
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
2017-12-29 22:27:32 +02:00
|
|
|
for _, task := range e.Taskfile.Tasks {
|
2017-03-19 20:18:18 +02:00
|
|
|
if task.Desc != "" {
|
2021-01-12 17:03:04 +02:00
|
|
|
compiledTask, err := e.FastCompiledTask(taskfile.Call{Task: task.Task})
|
2020-01-20 15:38:18 +02:00
|
|
|
if err == nil {
|
|
|
|
task = compiledTask
|
|
|
|
}
|
2017-12-29 22:27:32 +02:00
|
|
|
tasks = append(tasks, task)
|
2017-03-19 20:18:18 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-29 22:27:32 +02:00
|
|
|
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
|
2017-03-19 20:18:18 +02:00
|
|
|
return
|
|
|
|
}
|