forked from james-andrewsmith/task
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelp.go
102 lines (91 loc) · 2.42 KB
/
help.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package task
import (
_ "embed"
"encoding/base64"
"fmt"
"io"
"log"
"os"
"sort"
"strings"
"text/tabwriter"
"github.com/go-task/task/v3/internal/logger"
)
//go:embed logo.png
var logo []byte
func displaylogo() error {
// width, height := widthAndHeight()
width, height := "", ""
fmt.Print("\033]1337;")
fmt.Printf("File=inline=1")
if width != "" || height != "" {
if width != "" {
fmt.Printf(";width=%s", width)
}
if height != "" {
fmt.Printf(";height=%s", height)
}
}
// fmt.Print("preserveAspectRatio=1")
fmt.Print(":")
fmt.Printf("%s", base64.StdEncoding.EncodeToString(logo))
fmt.Print("\a\n")
return nil
}
// ListTasks prints a list of tasks.
// Tasks that match the given filters will be excluded from the list.
// The function returns a boolean indicating whether or not tasks were found.
func (e *Executor) ListTasks(filters ...FilterFunc) bool {
tasks := e.GetTaskList(filters...)
if len(tasks) == 0 {
return false
}
displaylogo()
e.Logger.Outf(logger.Default, "")
e.Logger.Outf(logger.Default, "Available tasks:")
// Format in tab-separated columns with a tab stop of 8.
w := tabwriter.NewWriter(e.Stdout, 0, 8, 6, ' ', 0)
for _, task := range tasks {
e.Logger.FOutf(w, logger.Yellow, "* ")
e.Logger.FOutf(w, logger.Green, task.Task)
e.Logger.FOutf(w, logger.Default, ": \t%s", task.Desc)
if len(task.Aliases) > 0 {
e.Logger.FOutf(w, logger.Cyan, "\t(aliases: %s)", strings.Join(task.Aliases, ", "))
}
fmt.Fprint(w, "\n")
}
w.Flush()
return true
}
// ListTaskNames 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 e.Taskfile == nil {
if err := e.readTaskfile(); err != nil {
log.Fatal(err)
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 != "") && !t.Internal {
s = append(s, strings.TrimRight(t.Task, ":"))
for _, alias := range t.Aliases {
s = append(s, strings.TrimRight(alias, ":"))
}
}
}
// sort and print all task names
sort.Strings(s)
for _, t := range s {
fmt.Fprintln(w, t)
}
}