mongo.go 992 B

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