go-zero/tools/goctl/api/tsgen/gen.go
kingxt ee19fb736b
feature: refactor api parse to g4 (#365)
* 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>
2021-01-11 15:10:51 +08:00

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
}