main.go 891 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "strings"
  9. )
  10. func regenerate(dir string) error {
  11. return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
  12. if err != nil {
  13. return err
  14. }
  15. if info.IsDir() {
  16. return nil
  17. }
  18. if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") {
  19. cwd := filepath.Dir(path)
  20. cmd := exec.Command("sqlc-dev", "generate", "--experimental")
  21. cmd.Dir = cwd
  22. failed := cmd.Run()
  23. if _, err := os.Stat(filepath.Join(cwd, "stderr.txt")); os.IsNotExist(err) && failed != nil {
  24. return fmt.Errorf("%s: sqlc-dev generate failed", cwd)
  25. }
  26. }
  27. return nil
  28. })
  29. }
  30. func main() {
  31. dirs := []string{
  32. filepath.Join("internal", "endtoend", "testdata"),
  33. filepath.Join("examples"),
  34. }
  35. for _, d := range dirs {
  36. if err := regenerate(d); err != nil {
  37. log.Fatal(err)
  38. }
  39. }
  40. }