-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
63 lines (54 loc) · 1.11 KB
/
util.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
package mageutil
import (
"context"
"strings"
"github.com/magefile/mage/mg"
)
type (
SerialFns []mg.Fn
ParallelFns []mg.Fn
)
func (s SerialFns) ID() string {
ids := make([]string, 0, len(s))
for _, f := range s {
ids = append(ids, f.ID())
}
return strings.Join(ids, ":")
}
func (s SerialFns) Name() string {
ids := make([]string, 0, len(s))
for _, f := range s {
ids = append(ids, f.Name())
}
return strings.Join(ids, ":")
}
func (s SerialFns) Run(ctx context.Context) error {
fns := make([]interface{}, 0, len(s))
for _, f := range s {
fns = append(fns, f)
}
mg.SerialCtxDeps(ctx, fns...)
return nil
}
func (p ParallelFns) ID() string {
ids := make([]string, 0, len(p))
for _, f := range p {
ids = append(ids, f.ID())
}
return strings.Join(ids, ":")
}
func (p ParallelFns) Name() string {
ids := make([]string, 0, len(p))
for _, f := range p {
ids = append(ids, f.Name())
}
return strings.Join(ids, ":")
}
func (p ParallelFns) Run(ctx context.Context) error {
fns := make([]interface{}, 0, len(p))
for _, f := range p {
fns = append(fns, f)
}
mg.CtxDeps(ctx, fns...)
return nil
}