forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
43 lines (40 loc) · 891 Bytes
/
main.go
File metadata and controls
43 lines (40 loc) · 891 Bytes
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
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func regenerate(dir string) error {
return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") {
cwd := filepath.Dir(path)
cmd := exec.Command("sqlc-dev", "generate", "--experimental")
cmd.Dir = cwd
failed := cmd.Run()
if _, err := os.Stat(filepath.Join(cwd, "stderr.txt")); os.IsNotExist(err) && failed != nil {
return fmt.Errorf("%s: sqlc-dev generate failed", cwd)
}
}
return nil
})
}
func main() {
dirs := []string{
filepath.Join("internal", "endtoend", "testdata"),
filepath.Join("examples"),
}
for _, d := range dirs {
if err := regenerate(d); err != nil {
log.Fatal(err)
}
}
}