@@ -55,8 +55,9 @@ func ApiCommand(c *cli.Context) error {
|
||||
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -33,8 +33,9 @@ func GoCommand(c *cli.Context) error {
|
||||
namingStyle := c.String("style")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -67,8 +67,9 @@ func CreateServiceCommand(c *cli.Context) error {
|
||||
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -46,8 +46,9 @@ func DockerCommand(c *cli.Context) (err error) {
|
||||
home := c.String("home")
|
||||
version := c.String("version")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -111,6 +111,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: apigen.ApiCommand,
|
||||
Subcommands: []cli.Command{
|
||||
@@ -130,6 +134,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "style",
|
||||
Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md]",
|
||||
@@ -209,6 +217,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: gogen.GoCommand,
|
||||
},
|
||||
@@ -345,6 +357,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "version",
|
||||
Usage: "the goctl builder golang image version",
|
||||
@@ -445,6 +461,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "serviceAccount",
|
||||
Usage: "the ServiceAccount for the deployment",
|
||||
@@ -482,6 +502,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: rpc.RPCNew,
|
||||
},
|
||||
@@ -504,6 +528,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: rpc.RPCTemplate,
|
||||
},
|
||||
@@ -548,6 +576,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -590,6 +622,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: rpc.RPC,
|
||||
},
|
||||
@@ -642,6 +678,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: model.MysqlDDL,
|
||||
},
|
||||
@@ -684,6 +724,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: model.MySqlDataSource,
|
||||
},
|
||||
@@ -736,6 +780,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: model.PostgreSqlDataSource,
|
||||
},
|
||||
@@ -772,6 +820,10 @@ var commands = []cli.Command{
|
||||
"if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
|
||||
"https://github.com/zeromicro/go-zero-template directory structure",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "the branch of the remote repo, it does work with --remote",
|
||||
},
|
||||
},
|
||||
Action: mongo.Action,
|
||||
},
|
||||
|
||||
@@ -44,8 +44,9 @@ func DeploymentCommand(c *cli.Context) error {
|
||||
nodePort := c.Int("nodePort")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ func Action(ctx *cli.Context) error {
|
||||
s := ctx.String("style")
|
||||
home := ctx.String("home")
|
||||
remote := ctx.String("remote")
|
||||
branch := ctx.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ const (
|
||||
flagDatabase = "database"
|
||||
flagSchema = "schema"
|
||||
flagHome = "home"
|
||||
flagRemote = "remote"
|
||||
flagBranch = "branch"
|
||||
)
|
||||
|
||||
var errNotMatched = errors.New("sql not matched")
|
||||
@@ -43,9 +45,10 @@ func MysqlDDL(ctx *cli.Context) error {
|
||||
style := ctx.String(flagStyle)
|
||||
database := ctx.String(flagDatabase)
|
||||
home := ctx.String(flagHome)
|
||||
remote := ctx.String("remote")
|
||||
remote := ctx.String(flagRemote)
|
||||
branch := ctx.String(flagBranch)
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -68,10 +71,11 @@ func MySqlDataSource(ctx *cli.Context) error {
|
||||
cache := ctx.Bool(flagCache)
|
||||
idea := ctx.Bool(flagIdea)
|
||||
style := ctx.String(flagStyle)
|
||||
home := ctx.String("home")
|
||||
remote := ctx.String("remote")
|
||||
home := ctx.String(flagHome)
|
||||
remote := ctx.String(flagRemote)
|
||||
branch := ctx.String(flagBranch)
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -97,10 +101,11 @@ func PostgreSqlDataSource(ctx *cli.Context) error {
|
||||
idea := ctx.Bool(flagIdea)
|
||||
style := ctx.String(flagStyle)
|
||||
schema := ctx.String(flagSchema)
|
||||
home := ctx.String("home")
|
||||
remote := ctx.String("remote")
|
||||
home := ctx.String(flagHome)
|
||||
remote := ctx.String(flagRemote)
|
||||
branch := ctx.String(flagBranch)
|
||||
if len(remote) > 0 {
|
||||
repo, _ := file.CloneIntoGitHome(remote)
|
||||
repo, _ := file.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -33,8 +33,9 @@ func RPC(c *cli.Context) error {
|
||||
goOptions := c.StringSlice("go_opt")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -89,8 +90,9 @@ func RPCNew(c *cli.Context) error {
|
||||
style := c.String("style")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
@@ -124,8 +126,9 @@ func RPCTemplate(c *cli.Context) error {
|
||||
protoFile := c.String("o")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -54,8 +54,9 @@ func ZRPC(c *cli.Context) error {
|
||||
style := c.String("style")
|
||||
home := c.String("home")
|
||||
remote := c.String("remote")
|
||||
branch := c.String("branch")
|
||||
if len(remote) > 0 {
|
||||
repo, _ := util.CloneIntoGitHome(remote)
|
||||
repo, _ := util.CloneIntoGitHome(remote, branch)
|
||||
if len(repo) > 0 {
|
||||
home = repo
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
func CloneIntoGitHome(url string) (dir string, err error) {
|
||||
func CloneIntoGitHome(url string, branch string) (dir string, err error) {
|
||||
gitHome, err := pathx.GetGitHome()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -21,6 +21,9 @@ func CloneIntoGitHome(url string) (dir string, err error) {
|
||||
ext := filepath.Ext(url)
|
||||
repo := strings.TrimSuffix(filepath.Base(url), ext)
|
||||
dir = filepath.Join(gitHome, repo)
|
||||
if pathx.FileExists(dir) {
|
||||
os.RemoveAll(dir)
|
||||
}
|
||||
path, err := env.LookPath("git")
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -28,7 +31,12 @@ func CloneIntoGitHome(url string) (dir string, err error) {
|
||||
if !env.CanExec() {
|
||||
return "", fmt.Errorf("os %q can not call 'exec' command", runtime.GOOS)
|
||||
}
|
||||
cmd := exec.Command(path, "clone", url, dir)
|
||||
args := []string{"clone"}
|
||||
if len(branch) > 0 {
|
||||
args = append(args, "-b", branch)
|
||||
}
|
||||
args = append(args, url, dir)
|
||||
cmd := exec.Command(path, args...)
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
Reference in New Issue
Block a user