gen.go 851 B

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