-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
50 lines (44 loc) · 1 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/complex64/protoc-gen-gorm/internal/gengorm"
"github.com/complex64/protoc-gen-gorm/internal/version"
"google.golang.org/protobuf/compiler/protogen"
)
const (
docURL = "https://github.com/complex64/protoc-gen-gorm"
)
var (
showVersion = flag.Bool("version", false, "")
showHelp = flag.Bool("help", false, "")
)
func main() {
flag.Parse()
if *showVersion {
fmt.Fprintf(os.Stdout, "%v %v\n", filepath.Base(os.Args[0]), version.String())
os.Exit(0)
}
if *showHelp {
fmt.Fprintf(os.Stdout, "Please see %s for usage information.\n", docURL)
os.Exit(0)
}
var (
flags flag.FlagSet
)
protogen.Options{
// Calls `flags.Set(param, value)` for each from `--gorm_out=<param1>=<value1>,...`.
ParamFunc: flags.Set,
}.Run(func(plugin *protogen.Plugin) error {
for _, f := range plugin.Files {
if f.Generate {
if err := gengorm.GenerateFile(flags, plugin, f); err != nil {
return err
}
}
}
return nil
})
}