mongo.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package mongo
  2. import (
  3. "errors"
  4. "path/filepath"
  5. "strings"
  6. "github.com/urfave/cli"
  7. "github.com/zeromicro/go-zero/tools/goctl/config"
  8. "github.com/zeromicro/go-zero/tools/goctl/model/mongo/generate"
  9. file "github.com/zeromicro/go-zero/tools/goctl/util"
  10. "github.com/zeromicro/go-zero/tools/goctl/util/pathx"
  11. )
  12. // Action provides the entry for goctl mongo code generation.
  13. func Action(ctx *cli.Context) error {
  14. tp := ctx.StringSlice("type")
  15. c := ctx.Bool("cache")
  16. o := strings.TrimSpace(ctx.String("dir"))
  17. s := ctx.String("style")
  18. home := ctx.String("home")
  19. remote := ctx.String("remote")
  20. if len(remote) > 0 {
  21. repo, _ := file.CloneIntoGitHome(remote)
  22. if len(repo) > 0 {
  23. home = repo
  24. }
  25. }
  26. if len(home) > 0 {
  27. pathx.RegisterGoctlHome(home)
  28. }
  29. if len(tp) == 0 {
  30. return errors.New("missing type")
  31. }
  32. cfg, err := config.NewConfig(s)
  33. if err != nil {
  34. return err
  35. }
  36. a, err := filepath.Abs(o)
  37. if err != nil {
  38. return err
  39. }
  40. return generate.Do(&generate.Context{
  41. Types: tp,
  42. Cache: c,
  43. Output: a,
  44. Cfg: cfg,
  45. })
  46. }