mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-27 12:28:40 +08:00
ee19fb736b
* feature: refactor api parse to g4 * new g4 parser * add CHANGE_LOG.MD * refactor * fix byte bug * refactor * optimized * optimized * revert * update readme.md * update readme.md * update readme.md * update readme.md * remove no need * fix java gen * add upgrade * resolve confilits Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
41 lines
842 B
Go
41 lines
842 B
Go
package tsgen
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/logrusorgru/aurora"
|
|
"github.com/tal-tech/go-zero/core/logx"
|
|
"github.com/tal-tech/go-zero/tools/goctl/api/parser"
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func TsCommand(c *cli.Context) error {
|
|
apiFile := c.String("api")
|
|
dir := c.String("dir")
|
|
webApi := c.String("webapi")
|
|
caller := c.String("caller")
|
|
unwrapApi := c.Bool("unwrap")
|
|
if len(apiFile) == 0 {
|
|
return errors.New("missing -api")
|
|
}
|
|
|
|
if len(dir) == 0 {
|
|
return errors.New("missing -dir")
|
|
}
|
|
|
|
api, err := parser.Parse(apiFile)
|
|
if err != nil {
|
|
fmt.Println(aurora.Red("Failed"))
|
|
return err
|
|
}
|
|
|
|
logx.Must(util.MkdirIfNotExist(dir))
|
|
logx.Must(genHandler(dir, webApi, caller, api, unwrapApi))
|
|
logx.Must(genComponents(dir, api))
|
|
|
|
fmt.Println(aurora.Green("Done."))
|
|
return nil
|
|
}
|