gen.go 897 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package javagen
  2. import (
  3. "errors"
  4. "fmt"
  5. "strings"
  6. "git.i2edu.net/i2/go-zero/core/logx"
  7. "git.i2edu.net/i2/go-zero/tools/goctl/api/parser"
  8. "git.i2edu.net/i2/go-zero/tools/goctl/util"
  9. "github.com/logrusorgru/aurora"
  10. "github.com/urfave/cli"
  11. )
  12. // JavaCommand the generate java code command entrance
  13. func JavaCommand(c *cli.Context) error {
  14. apiFile := c.String("api")
  15. dir := c.String("dir")
  16. if len(apiFile) == 0 {
  17. return errors.New("missing -api")
  18. }
  19. if len(dir) == 0 {
  20. return errors.New("missing -dir")
  21. }
  22. api, err := parser.Parse(apiFile)
  23. if err != nil {
  24. return err
  25. }
  26. packetName := api.Service.Name
  27. if strings.HasSuffix(packetName, "-api") {
  28. packetName = packetName[:len(packetName)-4]
  29. }
  30. logx.Must(util.MkdirIfNotExist(dir))
  31. logx.Must(genPacket(dir, packetName, api))
  32. logx.Must(genComponents(dir, packetName, api))
  33. fmt.Println(aurora.Green("Done."))
  34. return nil
  35. }