-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (43 loc) · 1.27 KB
/
main.go
File metadata and controls
49 lines (43 loc) · 1.27 KB
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
package main
import (
"flag"
"fmt"
"github.com/go-sphere/protoc-gen-sphere-binding/generate/binding"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
)
var (
showVersion = flag.Bool("version", false, "print the version and exit")
autoRemoveJson = flag.Bool("auto_remove_json", true, "automatically remove json tag if sphere binding location set")
bindingAliases = flag.String("binding_aliases", "", "example: query=form,uri=path,db=database. add additional tag aliases for any binding tag")
out = flag.String("out", "api", "output directory for generated files")
)
func main() {
flag.Parse()
if *showVersion {
fmt.Printf("protoc-gen-sphere-binding %v\n", "0.0.1")
return
}
protogen.Options{
ParamFunc: flag.CommandLine.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
aliases, err := binding.ParseBindingAliases(*bindingAliases)
if err != nil {
return err
}
for _, f := range gen.Files {
if !f.Generate {
continue
}
bErr := binding.GenerateFile(f, *out, &binding.Config{
AutoRemoveJson: *autoRemoveJson,
BindingAliases: aliases,
})
if bErr != nil {
return bErr
}
}
return nil
})
}