gen.go 842 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package tsgen
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/logrusorgru/aurora"
  6. "github.com/tal-tech/go-zero/core/logx"
  7. "github.com/tal-tech/go-zero/tools/goctl/api/parser"
  8. "github.com/tal-tech/go-zero/tools/goctl/util"
  9. "github.com/urfave/cli"
  10. )
  11. func TsCommand(c *cli.Context) error {
  12. apiFile := c.String("api")
  13. dir := c.String("dir")
  14. webApi := c.String("webapi")
  15. caller := c.String("caller")
  16. unwrapApi := c.Bool("unwrap")
  17. if len(apiFile) == 0 {
  18. return errors.New("missing -api")
  19. }
  20. if len(dir) == 0 {
  21. return errors.New("missing -dir")
  22. }
  23. api, err := parser.Parse(apiFile)
  24. if err != nil {
  25. fmt.Println(aurora.Red("Failed"))
  26. return err
  27. }
  28. logx.Must(util.MkdirIfNotExist(dir))
  29. logx.Must(genHandler(dir, webApi, caller, api, unwrapApi))
  30. logx.Must(genComponents(dir, api))
  31. fmt.Println(aurora.Green("Done."))
  32. return nil
  33. }