-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (52 loc) · 1.25 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
package main
import (
"flag"
"fmt"
"github.com/woaijssss/gtc/compile"
"os"
"os/exec"
"path/filepath"
)
var inputFile string
var pkgName string
var oPath string
func init() {
flag.StringVar(&inputFile, "i", "", "the create tables file")
flag.StringVar(&pkgName, "pkg", "", "package name for every go file")
flag.StringVar(&oPath, "o", "./", "output directory, default is current directory")
}
func main() {
flag.Parse()
if inputFile == "" {
fmt.Println("Please input create tables file")
os.Exit(1)
}
fmt.Println("Using create table files is: ", inputFile)
if pkgName == "" {
fmt.Println("Please input package name")
os.Exit(1)
}
fmt.Println("Using package name: ", pkgName)
if oPath == "./" {
fmt.Println("Using current directory as output: ./", pkgName)
} else {
fmt.Println("Using output file directory is: ", filepath.Join(oPath, pkgName))
}
data, err := os.ReadFile(inputFile)
if err != nil {
fmt.Println("Read input create tables file error.", err)
os.Exit(1)
}
sql := string(data)
compile.BuildTableMata(sql, pkgName, oPath)
targetPath := oPath
if oPath == "./" {
str, _ := os.Getwd()
targetPath = str + "/" + pkgName
}
cmd := exec.Command("go", "fmt", targetPath)
err = cmd.Run()
if err != nil {
fmt.Println(err)
}
}