mongo.go 710 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package mongo
  2. import (
  3. "errors"
  4. "path/filepath"
  5. "strings"
  6. "git.i2edu.net/i2/go-zero/tools/goctl/config"
  7. "git.i2edu.net/i2/go-zero/tools/goctl/model/mongo/generate"
  8. "github.com/urfave/cli"
  9. )
  10. // Action provides the entry for goctl mongo code generation.
  11. func Action(ctx *cli.Context) error {
  12. tp := ctx.StringSlice("type")
  13. c := ctx.Bool("cache")
  14. o := strings.TrimSpace(ctx.String("dir"))
  15. s := ctx.String("style")
  16. if len(tp) == 0 {
  17. return errors.New("missing type")
  18. }
  19. cfg, err := config.NewConfig(s)
  20. if err != nil {
  21. return err
  22. }
  23. a, err := filepath.Abs(o)
  24. if err != nil {
  25. return err
  26. }
  27. return generate.Do(&generate.Context{
  28. Types: tp,
  29. Cache: c,
  30. Output: a,
  31. Cfg: cfg,
  32. })
  33. }