-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (55 loc) · 1.88 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"github.com/infiniteloopcloud/jsongen/pkg/logger"
"github.com/infiniteloopcloud/jsongen/pkg/updater"
)
var version = "go1.20.1"
var destination = "../json_try"
func init() {
flag.StringVar(&version, "version", "go1.20.1", "Version you want to apply the generation (format: go1.20.1)")
flag.StringVar(&destination, "destination", "../json_try", "Location of the repository where you want to generate")
flag.Parse()
}
func main() {
logger.Info("Start to generate json generation for " + version + " to " + destination)
if version == "" {
logger.Error("You need to provide --version, format of the parameter should be: 'go1.X.X'")
}
if destination == "" {
logger.Error("You need to provide --destination")
}
logger.Info("Cleanup - remove the go files from the destination")
err := updater.Clean(destination)
if err != nil {
logger.Error(err.Error())
}
logger.Info("Download Go's tar.gz for the specified version")
source, err := updater.DownloadTarGz(version)
if err != nil {
logger.Error(err.Error())
}
logger.Info("Extract the tar.gz")
err = updater.ExtractTarGz(source, destination)
if err != nil {
logger.Error(err.Error())
}
logger.Info("Analyze AST and apply changes on the encode.go")
node, fset, err := updater.ParseAndModify(destination + "/encode.go")
if err != nil {
logger.Error(err.Error())
}
logger.Info("Persist the previous changes on the encode.go")
if err := updater.PersistChanges(node, fset, destination+"/encode.go"); err != nil {
logger.Error(err.Error())
}
logger.Info("Create interfaces.go")
if err := updater.CreateInterface(destination + "/interfaces.go"); err != nil {
logger.Error(err.Error())
}
logger.Info("Create interfaces_test.go")
if err := updater.CreateInterfaceTest(destination + "/interfaces_test.go"); err != nil {
logger.Error(err.Error())
}
logger.Info("Generation was successful")
}