MCPcopy
hub / github.com/sqlc-dev/sqlc / main

Function main

scripts/mirror-go-plugin/main.go:14–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func main() {
15 flag.Parse()
16 // Assume it exists
17 loc := flag.Arg(0)
18
19 dir := filepath.Join("internal", "codegen", "golang")
20 err := filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
21 if err != nil {
22 return err
23 }
24 if info.IsDir() {
25 return nil
26 }
27 contents, err := os.ReadFile(path)
28 if err != nil {
29 return err
30 }
31
32 newdir := filepath.Join(loc, "internal")
33 newpath := strings.Replace(path, dir, newdir, 1)
34
35 os.MkdirAll(filepath.Dir(newpath), 0755)
36
37 contents = bytes.ReplaceAll(contents,
38 []byte(`"github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"`),
39 []byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/opts"`))
40
41 contents = bytes.ReplaceAll(contents,
42 []byte(`"github.com/sqlc-dev/sqlc/internal/plugin"`),
43 []byte(`"github.com/sqlc-dev/plugin-sdk-go/plugin"`))
44
45 contents = bytes.ReplaceAll(contents,
46 []byte(`"github.com/sqlc-dev/sqlc/internal/codegen/sdk"`),
47 []byte(`"github.com/sqlc-dev/plugin-sdk-go/sdk"`))
48
49 contents = bytes.ReplaceAll(contents,
50 []byte(`"github.com/sqlc-dev/sqlc/internal/metadata"`),
51 []byte(`"github.com/sqlc-dev/plugin-sdk-go/metadata"`))
52
53 contents = bytes.ReplaceAll(contents,
54 []byte(`"github.com/sqlc-dev/sqlc/internal/pattern"`),
55 []byte(`"github.com/sqlc-dev/plugin-sdk-go/pattern"`))
56
57 contents = bytes.ReplaceAll(contents,
58 []byte(`"github.com/sqlc-dev/sqlc/internal/debug"`),
59 []byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/debug"`))
60
61 contents = bytes.ReplaceAll(contents,
62 []byte(`"github.com/sqlc-dev/sqlc/internal/inflection"`),
63 []byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/inflection"`))
64
65 if err := os.WriteFile(newpath, contents, 0644); err != nil {
66 return err
67 }
68 return nil
69 })
70
71 if err != nil {

Callers

nothing calls this directly

Calls 3

ParseMethod · 0.65
JoinMethod · 0.45
ReplaceMethod · 0.45

Tested by

no test coverage detected