/
chaingen.go
48 lines (43 loc) · 1.35 KB
/
chaingen.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
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"github.com/AnatolyRugalev/chaingen/pkg/chaingen"
)
var (
flags = flag.NewFlagSet("chaingen", flag.ExitOnError)
options = &chaingen.Options{}
)
func init() {
wd, _ := os.Getwd()
flags.StringVar(&options.Src, "src", wd, "Builder package directory")
flags.StringVar(&options.TypeName, "type", "", "Builder type names, separated by comma")
flags.BoolVar(&options.Recursive, "recursive", false, "Whether to recuresively generate code for nested builders")
flags.StringVar(&options.FileSuffix, "file-suffix", ".chaingen.go", "Generated file suffix, including '.go'")
flags.BoolVar(&options.ErrOnConflict, "err-on-conflict", true, "Whether to return error if method naming conflict is encountered")
flags.StringVar(&options.StructTag, "struct-tag", "chaingen", "Sets struct tag name to use")
flags.StringVar(&options.BuildTag, "build-tag", "chaingen", "Sets go build tag name that is used to ignore generated files while analyzing code")
}
func main() {
err := flags.Parse(os.Args[1:])
if err != nil {
log.Println(err.Error())
flags.Usage()
os.Exit(2)
}
options.Src, err = filepath.Abs(options.Src)
if err != nil {
fmt.Println(err.Error())
flags.Usage()
os.Exit(2)
}
err = chaingen.New(*options).Generate()
if err != nil {
fmt.Println(err.Error())
flags.Usage()
os.Exit(1)
}
}