-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
68 lines (60 loc) · 2.45 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
61
62
63
64
65
66
67
68
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
)
var (
modelDir = flag.String("model-dir", "", "specify the model directory; must be set")
modelNames = flag.String("model-names", "", "specify the comma-separated list of model name; must be set")
modelPkgPath = flag.String("model-pkg-path", "", "specify the package path corresponding to the model directory; automatically calculated by default")
modelPkgAlias = flag.String("model-pkg-alias", "", "specify a model package alias; default no alias")
daoDir = flag.String("dao-dir", "", "specify the output directory of dao files; must be set")
daoPkgPath = flag.String("dao-pkg-path", "", "specify the package path corresponding to the output directory of the dao files; automatically generated by default")
subPkgEnable = flag.Bool("sub-pkg-enable", false, "specify whether to enable sub package; default disable")
subPkgStyle = flag.String("sub-pkg-style", "kebab", "specify the generation style for sub package; options: kebab | underscore | lower | camel | pascal; default is kebab")
counterName = flag.String("counter-name", "", "specify the counter name; default is counter")
fileNameStyle = flag.String("file-style", "underscore", "specify the generation style for file; options: kebab | underscore | lower | camel | pascal; default is underscore")
)
// Usage is a replacement usage function for the flags package.
func usage() {
fmt.Fprintf(os.Stderr, "Usage of mongo-dao-generator:\n")
fmt.Fprintf(os.Stderr, "\tmongo-dao-generator [flags] -model-dir=. -model-names=T,T -dao-dir=./dao\n")
fmt.Fprintf(os.Stderr, "For more information, see:\n")
fmt.Fprintf(os.Stderr, "\thttps://github.com/dobyte/mongo-dao-generator\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults()
}
//go:generate mongo-dao-generator -type=Mail,User
func main() {
log.SetFlags(0)
log.SetPrefix("mongo-dao-generator: ")
flag.Usage = usage
flag.Parse()
if len(*modelDir) == 0 {
flag.Usage()
os.Exit(2)
}
if len(*modelNames) == 0 {
flag.Usage()
os.Exit(2)
}
if len(*daoDir) == 0 {
flag.Usage()
os.Exit(2)
}
newGenerator(&options{
daoDir: *daoDir,
daoPkgPath: *daoPkgPath,
modelDir: *modelDir,
modelNames: strings.Split(*modelNames, ","),
modelPkgPath: *modelPkgPath,
modelPkgAlias: *modelPkgAlias,
subPkgEnable: *subPkgEnable,
subPkgStyle: style(*subPkgStyle),
counterName: *counterName,
fileNameStyle: style(*fileNameStyle),
}).makeDao()
}