-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.go
More file actions
64 lines (50 loc) · 1.21 KB
/
Copy pathrunner.go
File metadata and controls
64 lines (50 loc) · 1.21 KB
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
package main
import (
"fmt"
"strings"
"github.com/moaqz/tsk/color"
)
func topologicalOrder(name string, tasks map[string]*Task) []string {
var order []string
visited := make(map[string]bool)
var dfs func(string)
dfs = func(current string) {
visited[current] = true
for _, dependency := range tasks[current].Deps {
if !visited[dependency] {
dfs(dependency)
}
}
order = append(order, current)
}
for _, dependency := range tasks[name].Deps {
if !visited[dependency] {
dfs(dependency)
}
}
order = append(order, name)
return order
}
func runFromTask(name string, cfg *ConfigFile) {
for i, taskName := range topologicalOrder(name, cfg.Tasks) {
task := cfg.Tasks[taskName]
if i != 0 {
fmt.Println()
}
fmt.Printf("%s %s %s\n",
color.Text("❯").Bold().Cyan(),
color.Text("Running task:").Bold(),
color.Text(task.Name).Cyan(),
)
if strings.TrimSpace(task.Description) != "" {
fmt.Printf(" %s\n", color.Text(task.Description).Gray())
}
fmt.Println()
if err := task.Run(); err != nil {
die(fmt.Sprintf("task %q failed: %v", task.Name, err), false)
}
fmt.Printf("\n%s\n",
color.Text(fmt.Sprintf("%q finished successfully.", task.Name)).Green(),
)
}
}