* fix issue #831 * fix typo Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
@@ -30,7 +30,11 @@ func GoCommand(c *cli.Context) error {
|
|||||||
apiFile := c.String("api")
|
apiFile := c.String("api")
|
||||||
dir := c.String("dir")
|
dir := c.String("dir")
|
||||||
namingStyle := c.String("style")
|
namingStyle := c.String("style")
|
||||||
|
home := c.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
util.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
if len(apiFile) == 0 {
|
if len(apiFile) == 0 {
|
||||||
return errors.New("missing -api")
|
return errors.New("missing -api")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ func DockerCommand(c *cli.Context) (err error) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
goFile := c.String("go")
|
goFile := c.String("go")
|
||||||
|
home := c.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
util.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
|
|
||||||
if len(goFile) == 0 {
|
if len(goFile) == 0 {
|
||||||
return errors.New("-go can't be empty")
|
return errors.New("-go can't be empty")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,10 @@ var (
|
|||||||
Name: "style",
|
Name: "style",
|
||||||
Usage: "the file naming format, see [https://github.com/tal-tech/go-zero/tree/master/tools/goctl/config/readme.md]",
|
Usage: "the file naming format, see [https://github.com/tal-tech/go-zero/tree/master/tools/goctl/config/readme.md]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: gogen.GoCommand,
|
Action: gogen.GoCommand,
|
||||||
},
|
},
|
||||||
@@ -234,6 +238,10 @@ var (
|
|||||||
Usage: "the port to expose, default none",
|
Usage: "the port to expose, default none",
|
||||||
Value: 0,
|
Value: 0,
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: docker.DockerCommand,
|
Action: docker.DockerCommand,
|
||||||
},
|
},
|
||||||
@@ -319,6 +327,10 @@ var (
|
|||||||
Usage: "the max replicas of deploy",
|
Usage: "the max replicas of deploy",
|
||||||
Value: 10,
|
Value: 10,
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: kube.DeploymentCommand,
|
Action: kube.DeploymentCommand,
|
||||||
},
|
},
|
||||||
@@ -340,6 +352,10 @@ var (
|
|||||||
Name: "idea",
|
Name: "idea",
|
||||||
Usage: "whether the command execution environment is from idea plugin. [optional]",
|
Usage: "whether the command execution environment is from idea plugin. [optional]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: rpc.RPCNew,
|
Action: rpc.RPCNew,
|
||||||
},
|
},
|
||||||
@@ -382,6 +398,10 @@ var (
|
|||||||
Name: "idea",
|
Name: "idea",
|
||||||
Usage: "whether the command execution environment is from idea plugin. [optional]",
|
Usage: "whether the command execution environment is from idea plugin. [optional]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: rpc.RPC,
|
Action: rpc.RPC,
|
||||||
},
|
},
|
||||||
@@ -423,6 +443,10 @@ var (
|
|||||||
Name: "database, db",
|
Name: "database, db",
|
||||||
Usage: "the name of database [optional]",
|
Usage: "the name of database [optional]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: model.MysqlDDL,
|
Action: model.MysqlDDL,
|
||||||
},
|
},
|
||||||
@@ -454,6 +478,10 @@ var (
|
|||||||
Name: "idea",
|
Name: "idea",
|
||||||
Usage: "for idea plugin [optional]",
|
Usage: "for idea plugin [optional]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: model.MySqlDataSource,
|
Action: model.MySqlDataSource,
|
||||||
},
|
},
|
||||||
@@ -495,6 +523,10 @@ var (
|
|||||||
Name: "idea",
|
Name: "idea",
|
||||||
Usage: "for idea plugin [optional]",
|
Usage: "for idea plugin [optional]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: model.PostgreSqlDataSource,
|
Action: model.PostgreSqlDataSource,
|
||||||
},
|
},
|
||||||
@@ -520,6 +552,10 @@ var (
|
|||||||
Name: "style",
|
Name: "style",
|
||||||
Usage: "the file naming format, see [https://github.com/tal-tech/go-zero/tree/master/tools/goctl/config/readme.md]",
|
Usage: "the file naming format, see [https://github.com/tal-tech/go-zero/tree/master/tools/goctl/config/readme.md]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: mongo.Action,
|
Action: mongo.Action,
|
||||||
},
|
},
|
||||||
@@ -541,13 +577,25 @@ var (
|
|||||||
Usage: "template operation",
|
Usage: "template operation",
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
{
|
{
|
||||||
Name: "init",
|
Name: "init",
|
||||||
Usage: "initialize the all templates(force update)",
|
Usage: "initialize the all templates(force update)",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: tpl.GenTemplates,
|
Action: tpl.GenTemplates,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "clean",
|
Name: "clean",
|
||||||
Usage: "clean the all cache templates",
|
Usage: "clean the all cache templates",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: tpl.CleanTemplates,
|
Action: tpl.CleanTemplates,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -558,6 +606,10 @@ var (
|
|||||||
Name: "category,c",
|
Name: "category,c",
|
||||||
Usage: "the category of template, enum [api,rpc,model,docker,kube]",
|
Usage: "the category of template, enum [api,rpc,model,docker,kube]",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: tpl.UpdateTemplates,
|
Action: tpl.UpdateTemplates,
|
||||||
},
|
},
|
||||||
@@ -573,6 +625,10 @@ var (
|
|||||||
Name: "name,n",
|
Name: "name,n",
|
||||||
Usage: "the target file name of template",
|
Usage: "the target file name of template",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "home",
|
||||||
|
Usage: "the goctl home path of the template",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: tpl.RevertTemplates,
|
Action: tpl.RevertTemplates,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ type Deployment struct {
|
|||||||
// DeploymentCommand is used to generate the kubernetes deployment yaml files.
|
// DeploymentCommand is used to generate the kubernetes deployment yaml files.
|
||||||
func DeploymentCommand(c *cli.Context) error {
|
func DeploymentCommand(c *cli.Context) error {
|
||||||
nodePort := c.Int("nodePort")
|
nodePort := c.Int("nodePort")
|
||||||
|
home := c.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
util.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
|
|
||||||
// 0 to disable the nodePort type
|
// 0 to disable the nodePort type
|
||||||
if nodePort != 0 && (nodePort < basePort || nodePort > portLimit) {
|
if nodePort != 0 && (nodePort < basePort || nodePort > portLimit) {
|
||||||
return errors.New("nodePort should be between 30000 and 32767")
|
return errors.New("nodePort should be between 30000 and 32767")
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/config"
|
"github.com/tal-tech/go-zero/tools/goctl/config"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/model/mongo/generate"
|
"github.com/tal-tech/go-zero/tools/goctl/model/mongo/generate"
|
||||||
|
file "github.com/tal-tech/go-zero/tools/goctl/util"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,6 +17,12 @@ func Action(ctx *cli.Context) error {
|
|||||||
c := ctx.Bool("cache")
|
c := ctx.Bool("cache")
|
||||||
o := strings.TrimSpace(ctx.String("dir"))
|
o := strings.TrimSpace(ctx.String("dir"))
|
||||||
s := ctx.String("style")
|
s := ctx.String("style")
|
||||||
|
home := ctx.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
file.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
|
|
||||||
if len(tp) == 0 {
|
if len(tp) == 0 {
|
||||||
return errors.New("missing type")
|
return errors.New("missing type")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/tal-tech/go-zero/tools/goctl/model/sql/gen"
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/gen"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/model/sql/model"
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/model"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/model/sql/util"
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/util"
|
||||||
|
file "github.com/tal-tech/go-zero/tools/goctl/util"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/util/console"
|
"github.com/tal-tech/go-zero/tools/goctl/util/console"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@@ -39,6 +40,11 @@ func MysqlDDL(ctx *cli.Context) error {
|
|||||||
idea := ctx.Bool(flagIdea)
|
idea := ctx.Bool(flagIdea)
|
||||||
style := ctx.String(flagStyle)
|
style := ctx.String(flagStyle)
|
||||||
database := ctx.String(flagDatabase)
|
database := ctx.String(flagDatabase)
|
||||||
|
home := ctx.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
file.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
cfg, err := config.NewConfig(style)
|
cfg, err := config.NewConfig(style)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -54,6 +60,12 @@ func MySqlDataSource(ctx *cli.Context) error {
|
|||||||
cache := ctx.Bool(flagCache)
|
cache := ctx.Bool(flagCache)
|
||||||
idea := ctx.Bool(flagIdea)
|
idea := ctx.Bool(flagIdea)
|
||||||
style := ctx.String(flagStyle)
|
style := ctx.String(flagStyle)
|
||||||
|
home := ctx.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
file.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
|
|
||||||
pattern := strings.TrimSpace(ctx.String(flagTable))
|
pattern := strings.TrimSpace(ctx.String(flagTable))
|
||||||
cfg, err := config.NewConfig(style)
|
cfg, err := config.NewConfig(style)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -71,6 +83,12 @@ func PostgreSqlDataSource(ctx *cli.Context) error {
|
|||||||
idea := ctx.Bool(flagIdea)
|
idea := ctx.Bool(flagIdea)
|
||||||
style := ctx.String(flagStyle)
|
style := ctx.String(flagStyle)
|
||||||
schema := ctx.String(flagSchema)
|
schema := ctx.String(flagSchema)
|
||||||
|
home := ctx.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
file.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
|
|
||||||
if len(schema) == 0 {
|
if len(schema) == 0 {
|
||||||
schema = "public"
|
schema = "public"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/rpc/generator"
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/generator"
|
||||||
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,9 +19,16 @@ func RPC(c *cli.Context) error {
|
|||||||
style := c.String("style")
|
style := c.String("style")
|
||||||
protoImportPath := c.StringSlice("proto_path")
|
protoImportPath := c.StringSlice("proto_path")
|
||||||
goOptions := c.StringSlice("go_opt")
|
goOptions := c.StringSlice("go_opt")
|
||||||
|
home := c.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
util.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
|
|
||||||
if len(src) == 0 {
|
if len(src) == 0 {
|
||||||
return errors.New("missing -src")
|
return errors.New("missing -src")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(out) == 0 {
|
if len(out) == 0 {
|
||||||
return errors.New("missing -dir")
|
return errors.New("missing -dir")
|
||||||
}
|
}
|
||||||
@@ -42,6 +50,11 @@ func RPCNew(c *cli.Context) error {
|
|||||||
return fmt.Errorf("unexpected ext: %s", ext)
|
return fmt.Errorf("unexpected ext: %s", ext)
|
||||||
}
|
}
|
||||||
style := c.String("style")
|
style := c.String("style")
|
||||||
|
home := c.String("home")
|
||||||
|
|
||||||
|
if len(home) > 0 {
|
||||||
|
util.RegisterGoctlHome(home)
|
||||||
|
}
|
||||||
|
|
||||||
protoName := rpcname + ".proto"
|
protoName := rpcname + ".proto"
|
||||||
filename := filepath.Join(".", rpcname, protoName)
|
filename := filepath.Join(".", rpcname, protoName)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package tpl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
"github.com/tal-tech/go-zero/core/errorx"
|
"github.com/tal-tech/go-zero/core/errorx"
|
||||||
@@ -19,6 +20,11 @@ const templateParentPath = "/"
|
|||||||
|
|
||||||
// GenTemplates writes the latest template text into file which is not exists
|
// GenTemplates writes the latest template text into file which is not exists
|
||||||
func GenTemplates(ctx *cli.Context) error {
|
func GenTemplates(ctx *cli.Context) error {
|
||||||
|
path := ctx.String("home")
|
||||||
|
if len(path) != 0 {
|
||||||
|
util.RegisterGoctlHome(path)
|
||||||
|
}
|
||||||
|
|
||||||
if err := errorx.Chain(
|
if err := errorx.Chain(
|
||||||
func() error {
|
func() error {
|
||||||
return gogen.GenTemplates(ctx)
|
return gogen.GenTemplates(ctx)
|
||||||
@@ -47,14 +53,24 @@ func GenTemplates(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Templates are generated in %s, %s\n", aurora.Green(dir),
|
abs, err := filepath.Abs(dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Templates are generated in %s, %s\n", aurora.Green(abs),
|
||||||
aurora.Red("edit on your risk!"))
|
aurora.Red("edit on your risk!"))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanTemplates deletes all templates
|
// CleanTemplates deletes all templates
|
||||||
func CleanTemplates(_ *cli.Context) error {
|
func CleanTemplates(ctx *cli.Context) error {
|
||||||
|
path := ctx.String("home")
|
||||||
|
if len(path) != 0 {
|
||||||
|
util.RegisterGoctlHome(path)
|
||||||
|
}
|
||||||
|
|
||||||
err := errorx.Chain(
|
err := errorx.Chain(
|
||||||
func() error {
|
func() error {
|
||||||
return gogen.Clean()
|
return gogen.Clean()
|
||||||
@@ -86,7 +102,12 @@ func CleanTemplates(_ *cli.Context) error {
|
|||||||
// UpdateTemplates writes the latest template text into file,
|
// UpdateTemplates writes the latest template text into file,
|
||||||
// it will delete the older templates if there are exists
|
// it will delete the older templates if there are exists
|
||||||
func UpdateTemplates(ctx *cli.Context) (err error) {
|
func UpdateTemplates(ctx *cli.Context) (err error) {
|
||||||
|
path := ctx.String("home")
|
||||||
category := ctx.String("category")
|
category := ctx.String("category")
|
||||||
|
if len(path) != 0 {
|
||||||
|
util.RegisterGoctlHome(path)
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Println(aurora.Green(fmt.Sprintf("%s template are update!", category)).String())
|
fmt.Println(aurora.Green(fmt.Sprintf("%s template are update!", category)).String())
|
||||||
@@ -113,8 +134,13 @@ func UpdateTemplates(ctx *cli.Context) (err error) {
|
|||||||
|
|
||||||
// RevertTemplates will overwrite the old template content with the new template
|
// RevertTemplates will overwrite the old template content with the new template
|
||||||
func RevertTemplates(ctx *cli.Context) (err error) {
|
func RevertTemplates(ctx *cli.Context) (err error) {
|
||||||
|
path := ctx.String("home")
|
||||||
category := ctx.String("category")
|
category := ctx.String("category")
|
||||||
filename := ctx.String("name")
|
filename := ctx.String("name")
|
||||||
|
if len(path) != 0 {
|
||||||
|
util.RegisterGoctlHome(path)
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Println(aurora.Green(fmt.Sprintf("%s template are reverted!", filename)).String())
|
fmt.Println(aurora.Green(fmt.Sprintf("%s template are reverted!", filename)).String())
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ const (
|
|||||||
goctlDir = ".goctl"
|
goctlDir = ".goctl"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var goctlHome string
|
||||||
|
|
||||||
|
func RegisterGoctlHome(home string) {
|
||||||
|
goctlHome = home
|
||||||
|
}
|
||||||
|
|
||||||
// CreateIfNotExist creates a file if it is not exists
|
// CreateIfNotExist creates a file if it is not exists
|
||||||
func CreateIfNotExist(file string) (*os.File, error) {
|
func CreateIfNotExist(file string) (*os.File, error) {
|
||||||
_, err := os.Stat(file)
|
_, err := os.Stat(file)
|
||||||
@@ -62,6 +68,10 @@ func FileNameWithoutExt(file string) string {
|
|||||||
|
|
||||||
// GetGoctlHome returns the path value of the goctl home where Join $HOME with .goctl
|
// GetGoctlHome returns the path value of the goctl home where Join $HOME with .goctl
|
||||||
func GetGoctlHome() (string, error) {
|
func GetGoctlHome() (string, error) {
|
||||||
|
if len(goctlHome) != 0 {
|
||||||
|
return goctlHome, nil
|
||||||
|
}
|
||||||
|
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user