-
Notifications
You must be signed in to change notification settings - Fork 12
/
magefile.go
51 lines (41 loc) · 893 Bytes
/
magefile.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
//go:build mage
package main
import (
"golang.org/x/tools/txtar"
"os"
"path/filepath"
"strings"
)
// Clean cleans all the output from corpus txtar files
func Clean() error {
return filepath.Walk("./testdata", cleanTxtarOut)
}
func cleanTxtarOut(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}
if filepath.Ext(path) != ".txtar" {
return nil
}
data, err := os.ReadFile(path)
if err != nil {
return err
}
archive := txtar.Parse(data)
archive.Files = filter(
archive.Files,
func(t txtar.File) bool {
return !strings.HasPrefix(t.Name, "out")
},
)
return os.WriteFile(path, txtar.Format(archive), 0666)
}
func filter(ff []txtar.File, criteria func(f txtar.File) bool) []txtar.File {
filtered := make([]txtar.File, 0, len(ff))
for _, f := range ff {
if criteria(f) {
filtered = append(filtered, f)
}
}
return filtered
}