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:
@@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/logrusorgru/aurora"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
apiformat "github.com/zeromicro/go-zero/tools/goctl/api/format"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/api/parser"
|
||||
@@ -24,16 +24,30 @@ import (
|
||||
|
||||
const tmpFile = "%s-%d"
|
||||
|
||||
var tmpDir = path.Join(os.TempDir(), "goctl")
|
||||
var (
|
||||
tmpDir = path.Join(os.TempDir(), "goctl")
|
||||
// VarStringDir describes the directory.
|
||||
VarStringDir string
|
||||
// VarStringAPI describes the API.
|
||||
VarStringAPI string
|
||||
// VarStringHome describes the go home.
|
||||
VarStringHome string
|
||||
// VarStringRemote describes the remote git repository.
|
||||
VarStringRemote string
|
||||
// VarStringBranch describes the branch.
|
||||
VarStringBranch string
|
||||
// VarStringStyle describes the style of output files.
|
||||
VarStringStyle string
|
||||
)
|
||||
|
||||
// GoCommand gen go project files from command line
|
||||
func GoCommand(c *cli.Context) error {
|
||||
apiFile := c.String("api")
|
||||
dir := c.String("dir")
|
||||
namingStyle := c.String("style")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
func GoCommand(_ *cobra.Command, _ []string) error {
|
||||
apiFile := VarStringAPI
|
||||
dir := VarStringDir
|
||||
namingStyle := VarStringStyle
|
||||
home := VarStringHome
|
||||
remote := VarStringRemote
|
||||
branch := VarStringBranch
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
|
||||
@@ -3,7 +3,6 @@ package gogen
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
@@ -45,7 +44,7 @@ func Clean() error {
|
||||
}
|
||||
|
||||
// GenTemplates generates api template files.
|
||||
func GenTemplates(_ *cli.Context) error {
|
||||
func GenTemplates() error {
|
||||
return pathx.InitTemplates(category, templates)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user