-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (45 loc) · 856 Bytes
/
main.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
package main
import (
"fmt"
"go/parser"
"go/token"
"io"
"os"
replica "github.com/ethanperry1/replica/parser"
"strings"
)
func main() {
err := run()
if err != nil {
panic(err)
}
}
func run() error {
fset := token.NewFileSet()
file := os.Getenv("GOFILE")
f, err := parser.ParseFile(fset, file, nil, parser.ParseComments)
if err != nil {
return err
}
renderer, err := replica.NewRenderer()
if err != nil {
return err
}
writer := replica.NewWriter(renderer)
creator := replica.New()
mockFile := creator.CreateMockFile(f)
reader, err := writer.Generate(mockFile)
if err != nil {
return err
}
content, err := io.ReadAll(reader)
if err != nil {
return err
}
mock, err := os.Create(fmt.Sprintf("%s_mocks.go", strings.Trim(file, ".go")))
if err != nil {
return err
}
_, err = mock.Write(content)
return err
}