2020-08-14 09:02:32 +08:00
|
|
|
package ktgen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-08-14 10:35:35 +08:00
|
|
|
|
2020-08-14 09:02:32 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/api/parser"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2021-02-26 16:11:47 +08:00
|
|
|
// KtCommand the generate kotlin code command entrance
|
2020-08-14 09:02:32 +08:00
|
|
|
func KtCommand(c *cli.Context) error {
|
|
|
|
apiFile := c.String("api")
|
|
|
|
if apiFile == "" {
|
|
|
|
return errors.New("missing -api")
|
|
|
|
}
|
|
|
|
dir := c.String("dir")
|
|
|
|
if dir == "" {
|
|
|
|
return errors.New("missing -dir")
|
|
|
|
}
|
|
|
|
pkg := c.String("pkg")
|
|
|
|
if pkg == "" {
|
|
|
|
return errors.New("missing -pkg")
|
|
|
|
}
|
|
|
|
|
2021-01-11 15:10:51 +08:00
|
|
|
api, e := parser.Parse(apiFile)
|
2020-08-14 10:35:35 +08:00
|
|
|
if e != nil {
|
|
|
|
return e
|
2020-08-14 09:02:32 +08:00
|
|
|
}
|
|
|
|
|
2020-08-14 19:25:34 +08:00
|
|
|
e = genBase(dir, pkg, api)
|
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
e = genApi(dir, pkg, api)
|
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
2020-08-14 09:02:32 +08:00
|
|
|
return nil
|
|
|
|
}
|