feat: Replace cli to cobra (#1855)

* Replace cli

* Replace cli

* Replace cli

* Format code

* Add compare case

* Add compare case

* Add compare case

* Support go style flag

* Support go style flag

* Add test case
This commit is contained in:
anqiansong
2022-05-07 15:40:11 +08:00
committed by GitHub
parent 51472004a3
commit 5383e29ce6
61 changed files with 1858 additions and 1590 deletions

View File

@@ -3,7 +3,6 @@ package generate
import (
"fmt"
"github.com/urfave/cli"
"github.com/zeromicro/go-zero/tools/goctl/model/mongo/template"
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
)
@@ -30,7 +29,7 @@ func Clean() error {
}
// Templates initializes the mongo templates.
func Templates(_ *cli.Context) error {
func Templates() error {
return pathx.InitTemplates(category, templates)
}

View File

@@ -5,22 +5,39 @@ import (
"path/filepath"
"strings"
"github.com/urfave/cli"
"github.com/spf13/cobra"
"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"
)
var (
// VarStringSliceType describes a golang data structure name for mongo.
VarStringSliceType []string
// VarStringDir describes an output directory.
VarStringDir string
// VarBoolCache describes whether cache is enabled.
VarBoolCache bool
// VarStringStyle describes the style.
VarStringStyle string
// VarStringHome describes the goctl home.
VarStringHome string
// VarStringRemote describes the remote git repository.
VarStringRemote string
// VarStringBranch describes the git branch.
VarStringBranch string
)
// 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")
func Action(_ *cobra.Command, _ []string) error {
tp := VarStringSliceType
c := VarBoolCache
o := strings.TrimSpace(VarStringDir)
s := VarStringStyle
home := VarStringHome
remote := VarStringRemote
branch := VarStringBranch
if len(remote) > 0 {
repo, _ := file.CloneIntoGitHome(remote, branch)
if len(repo) > 0 {