2021-03-12 17:49:28 +08:00
|
|
|
package mongo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/config"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/model/mongo/generate"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2021-03-12 23:08:04 +08:00
|
|
|
// Action provides the entry for goctl mongo code generation.
|
2021-03-12 17:49:28 +08:00
|
|
|
func Action(ctx *cli.Context) error {
|
|
|
|
tp := ctx.StringSlice("type")
|
|
|
|
c := ctx.Bool("cache")
|
|
|
|
o := strings.TrimSpace(ctx.String("dir"))
|
|
|
|
s := ctx.String("style")
|
|
|
|
if len(tp) == 0 {
|
|
|
|
return errors.New("missing type")
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := config.NewConfig(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
a, err := filepath.Abs(o)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return generate.Do(&generate.Context{
|
|
|
|
Types: tp,
|
|
|
|
Cache: c,
|
|
|
|
Output: a,
|
|
|
|
Cfg: cfg,
|
|
|
|
})
|
|
|
|
}
|