-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
109 lines (94 loc) · 2.95 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"flag"
"fmt"
"github.com/mirzaakhena/gogen/command/genapplication"
"github.com/mirzaakhena/gogen/command/gencontroller"
"github.com/mirzaakhena/gogen/command/gencrud"
"github.com/mirzaakhena/gogen/command/gendomain"
"github.com/mirzaakhena/gogen/command/genentity"
"github.com/mirzaakhena/gogen/command/genenum"
"github.com/mirzaakhena/gogen/command/generror"
"github.com/mirzaakhena/gogen/command/gengateway"
"github.com/mirzaakhena/gogen/command/genrepository"
"github.com/mirzaakhena/gogen/command/genservice"
"github.com/mirzaakhena/gogen/command/gentest"
"github.com/mirzaakhena/gogen/command/genusecase"
"github.com/mirzaakhena/gogen/command/genvalueobject"
"github.com/mirzaakhena/gogen/command/genvaluestring"
"github.com/mirzaakhena/gogen/command/genweb"
"github.com/mirzaakhena/gogen/command/genwebapp"
)
var Version = "v0.0.23"
func main() {
type C struct {
Command string
Func func(...string) error
}
commands := make([]C, 0)
commands = append(commands,
C{"domain", gendomain.Run},
C{"entity", genentity.Run},
C{"valueobject", genvalueobject.Run},
C{"valuestring", genvaluestring.Run},
C{"enum", genenum.Run},
C{"usecase", genusecase.Run},
C{"repository", genrepository.Run},
C{"service", genservice.Run},
C{"test", gentest.Run},
C{"gateway", gengateway.Run},
C{"controller", gencontroller.Run},
C{"error", generror.Run},
C{"application", genapplication.Run},
C{"crud", gencrud.Run},
C{"webapp", genwebapp.Run},
C{"web", genweb.Run},
)
commandMap := map[string]func(...string) error{}
for _, c := range commands {
commandMap[c.Command] = c.Func
}
//commandMap := map[string]func(...string) error{
// "domain": gendomain.Run, // dom
// "usecase": genusecase.Run, // uc
// "entity": genentity.Run, // ent
// "valueobject": genvalueobject.Run, // vo
// "valuestring": genvaluestring.Run, // vs
// "enum": genenum.Run, // enum
// "repository": genrepository.Run, // repo
// "service": genservice.Run, // svc
// "test": gentest.Run, // test
// "gateway": gengateway.Run, // gtw
// "controller": gencontroller.Run, // ctl
// "error": generror.Run, // err
// "application": genapplication.Run, // app
// "crud": gencrud.Run, // crud
// // "webapp": genwebapp.Run, //
// // "web": genweb.Run, // web
// // "openapi": genopenapi.Run, //
//}
flag.Parse()
cmd := flag.Arg(0)
if cmd == "" {
fmt.Printf("Gogen %s\n", Version)
fmt.Printf("Try one of this command to learn how to use it\n")
for _, k := range commands {
fmt.Printf(" gogen %s\n", k.Command)
}
return
}
var values = make([]string, 0)
if flag.NArg() > 1 {
values = flag.Args()[1:]
}
f, exists := commandMap[cmd]
if !exists {
fmt.Printf("Command %s is not recognized\n", cmd)
return
}
err := f(values...)
if err != nil {
fmt.Printf("%s\n", err.Error())
return
}
}