Skip to content

Commit

Permalink
fix issue of default migrate version (#1536)
Browse files Browse the repository at this point in the history
* fix issue of default migrate version

* chore: update console colors
  • Loading branch information
kevwan authored Feb 14, 2022
1 parent 6ab0515 commit 6deb806
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 0 additions & 2 deletions tools/goctl/api/parser/g4/gen/api/apiparser_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,3 @@ func NewSyntaxLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, in

return p
}


16 changes: 10 additions & 6 deletions tools/goctl/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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
}
6 changes: 4 additions & 2 deletions tools/goctl/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 8 additions & 4 deletions tools/goctl/migrate/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions tools/goctl/util/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down Expand Up @@ -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{}) {
Expand Down

0 comments on commit 6deb806

Please sign in to comment.