From 6deb80625d57cc01f3db68e79b971d60da1b7e63 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Mon, 14 Feb 2022 23:09:32 +0800 Subject: [PATCH] fix issue of default migrate version (#1536) * fix issue of default migrate version * chore: update console colors --- .../api/parser/g4/gen/api/apiparser_parser.go | 2 -- tools/goctl/completion/completion.go | 16 ++++++++++------ tools/goctl/migrate/migrate.go | 6 ++++-- tools/goctl/migrate/mod.go | 12 ++++++++---- tools/goctl/util/console/console.go | 10 +++++----- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go b/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go index 39dce4be9f32..8599337c6169 100755 --- a/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go +++ b/tools/goctl/api/parser/g4/gen/api/apiparser_parser.go @@ -634,5 +634,3 @@ func NewSyntaxLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, in return p } - - diff --git a/tools/goctl/completion/completion.go b/tools/goctl/completion/completion.go index a6a6c3900bea..67493b998716 100644 --- a/tools/goctl/completion/completion.go +++ b/tools/goctl/completion/completion.go @@ -19,6 +19,7 @@ func Completion(c *cli.Context) error { if goos == vars.OsWindows { return fmt.Errorf("%q: only support unix-like OS", goos) } + name := c.String("name") if len(name) == 0 { name = defaultCompletionFilename @@ -31,6 +32,7 @@ func Completion(c *cli.Context) error { if err != nil { return err } + buffer := bytes.NewBuffer(nil) zshF := filepath.Join(home, "zsh", defaultCompletionFilename) err = pathx.MkdirIfNotExist(filepath.Dir(zshF)) @@ -43,7 +45,8 @@ func Completion(c *cli.Context) error { if err != nil { return err } - var flag = magic + + flag := magic err = ioutil.WriteFile(zshF, zsh, os.ModePerm) if err != nil { return err @@ -56,20 +59,21 @@ func Completion(c *cli.Context) error { } flag |= flagBash - buffer.WriteString(aurora.Green("generation auto completion success!\n").String()) - buffer.WriteString(aurora.Green("executes the following script to setting shell:\n").String()) + buffer.WriteString(aurora.BrightGreen("generation auto completion success!\n").String()) + buffer.WriteString(aurora.BrightGreen("executes the following script to setting shell:\n").String()) switch flag { case magic | flagZsh: - buffer.WriteString(aurora.Blue(fmt.Sprintf("echo PROG=goctl source %s >> ~/.zshrc && source ~/.zshrc", zshF)).String()) + buffer.WriteString(aurora.BrightCyan(fmt.Sprintf("echo PROG=goctl source %s >> ~/.zshrc && source ~/.zshrc", zshF)).String()) case magic | flagBash: - buffer.WriteString(aurora.Blue(fmt.Sprintf("echo PROG=goctl source %s >> ~/.bashrc && source ~/.bashrc", bashF)).String()) + buffer.WriteString(aurora.BrightCyan(fmt.Sprintf("echo PROG=goctl source %s >> ~/.bashrc && source ~/.bashrc", bashF)).String()) case magic | flagZsh | flagBash: - buffer.WriteString(aurora.Blue(fmt.Sprintf(`echo PROG=goctl source %s >> ~/.zshrc && source ~/.zshrc + buffer.WriteString(aurora.BrightCyan(fmt.Sprintf(`echo PROG=goctl source %s >> ~/.zshrc && source ~/.zshrc or echo PROG=goctl source %s >> ~/.bashrc && source ~/.bashrc`, zshF, bashF)).String()) default: return nil } + fmt.Println(buffer.String()) return nil } diff --git a/tools/goctl/migrate/migrate.go b/tools/goctl/migrate/migrate.go index 24d0f52494f1..b7b5082e283c 100644 --- a/tools/goctl/migrate/migrate.go +++ b/tools/goctl/migrate/migrate.go @@ -22,7 +22,7 @@ import ( "github.com/zeromicro/go-zero/tools/goctl/vars" ) -const zeromicroVersion = "1.3.0" +const zeromicroVersion = "v1.3.0" const ( confirmUnknown = iota @@ -57,8 +57,10 @@ func Migrate(c *cli.Context) error { } if verbose { - console.Success("[OK] refactor finish, execute %q on project root to check status.", "go test -race ./...") + console.Success("[OK] refactor finish, execute %q on project root to check status.", + "go test -race ./...") } + return nil } diff --git a/tools/goctl/migrate/mod.go b/tools/goctl/migrate/mod.go index 408f63e492d8..74a54b7ba8e8 100644 --- a/tools/goctl/migrate/mod.go +++ b/tools/goctl/migrate/mod.go @@ -12,10 +12,12 @@ import ( "github.com/zeromicro/go-zero/tools/goctl/util/ctx" ) -const deprecatedGoZeroMod = "github.com/tal-tech/go-zero" -const deprecatedBuilderx = "github.com/tal-tech/go-zero/tools/goctl/model/sql/builderx" -const replacementBuilderx = "github.com/zeromicro/go-zero/core/stores/builder" -const goZeroMod = "github.com/zeromicro/go-zero" +const ( + deprecatedGoZeroMod = "github.com/tal-tech/go-zero" + deprecatedBuilderx = "github.com/tal-tech/go-zero/tools/goctl/model/sql/builderx" + replacementBuilderx = "github.com/zeromicro/go-zero/core/stores/builder" + goZeroMod = "github.com/zeromicro/go-zero" +) var errInvalidGoMod = errors.New("it's only working for go module") @@ -38,11 +40,13 @@ func editMod(version string, verbose bool) error { if !stringx.Contains(latest, version) { return fmt.Errorf("release version %q is not found", version) } + mod := fmt.Sprintf("%s@%s", goZeroMod, version) err = removeRequire(deprecatedGoZeroMod, verbose) if err != nil { return err } + return addRequire(mod, verbose) } diff --git a/tools/goctl/util/console/console.go b/tools/goctl/util/console/console.go index 110ad28fefd1..7f160d9c6c80 100644 --- a/tools/goctl/util/console/console.go +++ b/tools/goctl/util/console/console.go @@ -50,22 +50,22 @@ func (c *colorConsole) Info(format string, a ...interface{}) { func (c *colorConsole) Debug(format string, a ...interface{}) { msg := fmt.Sprintf(format, a...) - println(aurora.Blue(msg)) + println(aurora.BrightCyan(msg)) } func (c *colorConsole) Success(format string, a ...interface{}) { msg := fmt.Sprintf(format, a...) - println(aurora.Green(msg)) + println(aurora.BrightGreen(msg)) } func (c *colorConsole) Warning(format string, a ...interface{}) { msg := fmt.Sprintf(format, a...) - println(aurora.Yellow(msg)) + println(aurora.BrightYellow(msg)) } func (c *colorConsole) Error(format string, a ...interface{}) { msg := fmt.Sprintf(format, a...) - println(aurora.Red(msg)) + println(aurora.BrightRed(msg)) } func (c *colorConsole) Fatalln(format string, a ...interface{}) { @@ -95,7 +95,7 @@ func (i *ideaConsole) Info(format string, a ...interface{}) { func (i *ideaConsole) Debug(format string, a ...interface{}) { msg := fmt.Sprintf(format, a...) - fmt.Println(aurora.Blue(msg)) + fmt.Println(aurora.BrightCyan(msg)) } func (i *ideaConsole) Success(format string, a ...interface{}) {