-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (55 loc) · 1.58 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 (
"errors"
"flag"
"fmt"
"github.com/ShuaiGao/protoc-gen-bic/internal"
"github.com/ShuaiGao/protoc-gen-bic/internal/js"
"github.com/ShuaiGao/protoc-gen-bic/internal/ts"
"github.com/ShuaiGao/protoc-gen-bic/internal/utils"
"os"
"path/filepath"
"google.golang.org/protobuf/compiler/protogen"
)
func main() {
if len(os.Args) == 2 && os.Args[1] == "--version" {
fmt.Fprintf(os.Stdout, "%v %v\n", filepath.Base(os.Args[0]), utils.VERSION)
os.Exit(0)
}
if len(os.Args) == 2 && os.Args[1] == "--help" {
os.Exit(0)
}
var (
flags flag.FlagSet
plugins = flags.String("plugins", "", "deprecated option")
)
autoValidate := flags.Bool("auto_validate", true, "自动通过validate校验")
tsDir := flags.String("ts_dir", "", "ts文件生成目录")
jsDir := flags.String("js_dir", "", "js文件生成目录")
permissionPKG := flags.String("permission_pkg", "", "权限校验包名")
flag.Parse()
protogen.Options{
ParamFunc: flags.Set,
}.Run(func(gen *protogen.Plugin) error {
if *plugins != "" {
return errors.New("protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC\n\n")
}
for _, f := range gen.Files {
if f.Generate {
if len(*permissionPKG) > 0 {
internal.PermissionPkg = *permissionPKG
}
if len(*tsDir) > 0 {
ts.GenerateTsFile(gen, f, *tsDir)
} else if len(*jsDir) > 0 {
js.GenerateJsFile(gen, f, *jsDir)
} else {
internal.AutoValidate = *autoValidate
internal.GenerateFile(gen, f)
}
}
}
gen.SupportedFeatures = internal.SupportedFeatures
return nil
})
}