2021-03-12 17:49:28 +08:00
|
|
|
package mongo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2022-02-09 17:22:52 +08:00
|
|
|
"github.com/urfave/cli"
|
2022-01-25 23:15:07 +08:00
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/config"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/model/mongo/generate"
|
|
|
|
file "github.com/zeromicro/go-zero/tools/goctl/util"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
2021-03-12 17:49:28 +08:00
|
|
|
)
|
|
|
|
|
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")
|
2021-07-28 16:32:15 +08:00
|
|
|
home := ctx.String("home")
|
2021-12-29 18:16:42 +08:00
|
|
|
remote := ctx.String("remote")
|
2022-03-05 22:52:32 +08:00
|
|
|
branch := ctx.String("branch")
|
2021-12-29 18:16:42 +08:00
|
|
|
if len(remote) > 0 {
|
2022-03-05 22:52:32 +08:00
|
|
|
repo, _ := file.CloneIntoGitHome(remote, branch)
|
2021-12-29 18:16:42 +08:00
|
|
|
if len(repo) > 0 {
|
|
|
|
home = repo
|
|
|
|
}
|
|
|
|
}
|
2021-07-28 16:32:15 +08:00
|
|
|
if len(home) > 0 {
|
2022-01-03 21:32:40 +08:00
|
|
|
pathx.RegisterGoctlHome(home)
|
2021-07-28 16:32:15 +08:00
|
|
|
}
|
|
|
|
|
2021-03-12 17:49:28 +08:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|