2017-03-19 20:18:18 +02:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sort"
|
|
|
|
"text/tabwriter"
|
2018-02-17 18:22:18 +02:00
|
|
|
|
2019-05-26 23:36:39 +02:00
|
|
|
"github.com/go-task/task/v2/internal/logger"
|
2018-11-05 01:23:35 +02:00
|
|
|
"github.com/go-task/task/v2/internal/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 {
|
2017-12-29 22:27:32 +02:00
|
|
|
fmt.Fprintf(w, "* %s: \t%s\n", task.Task, 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 != "" {
|
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
|
|
|
|
}
|