forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.go
45 lines (38 loc) · 918 Bytes
/
gen.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
package javagen
import (
"errors"
"fmt"
"strings"
"github.com/logrusorgru/aurora"
"github.com/yilefreedom/go-zero/core/logx"
"github.com/yilefreedom/go-zero/tools/goctl/api/parser"
"github.com/yilefreedom/go-zero/tools/goctl/util"
"github.com/urfave/cli"
)
func JavaCommand(c *cli.Context) error {
apiFile := c.String("api")
dir := c.String("dir")
if len(apiFile) == 0 {
return errors.New("missing -api")
}
if len(dir) == 0 {
return errors.New("missing -dir")
}
p, err := parser.NewParser(apiFile)
if err != nil {
return err
}
api, err := p.Parse()
if err != nil {
return err
}
packetName := api.Service.Name
if strings.HasSuffix(packetName, "-api") {
packetName = packetName[:len(packetName)-4]
}
logx.Must(util.MkdirIfNotExist(dir))
logx.Must(genPacket(dir, packetName, api))
logx.Must(genComponents(dir, packetName, api))
fmt.Println(aurora.Green("Done."))
return nil
}