gen.go 694 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dartgen
  2. import (
  3. "errors"
  4. "strings"
  5. "github.com/tal-tech/go-zero/core/logx"
  6. "github.com/tal-tech/go-zero/tools/goctl/api/parser"
  7. "github.com/urfave/cli"
  8. )
  9. func DartCommand(c *cli.Context) error {
  10. apiFile := c.String("api")
  11. dir := c.String("dir")
  12. if len(apiFile) == 0 {
  13. return errors.New("missing -api")
  14. }
  15. if len(dir) == 0 {
  16. return errors.New("missing -dir")
  17. }
  18. api, err := parser.Parse(apiFile)
  19. if err != nil {
  20. return err
  21. }
  22. if !strings.HasSuffix(dir, "/") {
  23. dir = dir + "/"
  24. }
  25. api.Info.Title = strings.Replace(apiFile, ".api", "", -1)
  26. logx.Must(genData(dir+"data/", api))
  27. logx.Must(genApi(dir+"api/", api))
  28. logx.Must(genVars(dir + "vars/"))
  29. return nil
  30. }