You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package mongo
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/urfave/cli"
|
|
"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"
|
|
)
|
|
|
|
// Action provides the entry for goctl mongo code generation.
|
|
func Action(ctx *cli.Context) error {
|
|
tp := ctx.StringSlice("type")
|
|
c := ctx.Bool("cache")
|
|
o := strings.TrimSpace(ctx.String("dir"))
|
|
s := ctx.String("style")
|
|
home := ctx.String("home")
|
|
remote := ctx.String("remote")
|
|
branch := ctx.String("branch")
|
|
if len(remote) > 0 {
|
|
repo, _ := file.CloneIntoGitHome(remote, branch)
|
|
if len(repo) > 0 {
|
|
home = repo
|
|
}
|
|
}
|
|
if len(home) > 0 {
|
|
pathx.RegisterGoctlHome(home)
|
|
}
|
|
|
|
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,
|
|
})
|
|
}
|