mongo.go 853 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. if len(home) > 0 {
  19. file.RegisterGoctlHome(home)
  20. }
  21. if len(tp) == 0 {
  22. return errors.New("missing type")
  23. }
  24. cfg, err := config.NewConfig(s)
  25. if err != nil {
  26. return err
  27. }
  28. a, err := filepath.Abs(o)
  29. if err != nil {
  30. return err
  31. }
  32. return generate.Do(&generate.Context{
  33. Types: tp,
  34. Cache: c,
  35. Output: a,
  36. Cfg: cfg,
  37. })
  38. }