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:
23
tools/goctl/migrate/cmd.go
Normal file
23
tools/goctl/migrate/cmd.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package migrate
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
var (
|
||||
boolVarVerbose bool
|
||||
stringVarVersion string
|
||||
// Cmd describes a migrate command.
|
||||
Cmd = &cobra.Command{
|
||||
Use: "migrate",
|
||||
Short: "Migrate from tal-tech to zeromicro",
|
||||
Long: "Migrate is a transition command to help users migrate their " +
|
||||
"projects from tal-tech to zeromicro version",
|
||||
RunE: migrate,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
Cmd.Flags().BoolVarP(&boolVarVerbose, "verbose", "v",
|
||||
false, "Verbose enables extra logging")
|
||||
Cmd.Flags().StringVar(&stringVarVersion, "version", defaultMigrateVersion,
|
||||
"The target release version of github.com/zeromicro/go-zero to migrate")
|
||||
}
|
||||
@@ -16,13 +16,13 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/logrusorgru/aurora"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/console"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/ctx"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
||||
)
|
||||
|
||||
const zeromicroVersion = "v1.3.0"
|
||||
const defaultMigrateVersion = "v1.3.0"
|
||||
|
||||
const (
|
||||
confirmUnknown = iota
|
||||
@@ -35,28 +35,26 @@ var (
|
||||
builderxConfirm = confirmUnknown
|
||||
)
|
||||
|
||||
func Migrate(c *cli.Context) error {
|
||||
verbose := c.Bool("verbose")
|
||||
version := c.String("version")
|
||||
if len(version) == 0 {
|
||||
version = zeromicroVersion
|
||||
func migrate(_ *cobra.Command, _ []string) error {
|
||||
if len(stringVarVersion) == 0 {
|
||||
stringVarVersion = defaultMigrateVersion
|
||||
}
|
||||
err := editMod(version, verbose)
|
||||
err := editMod(stringVarVersion, boolVarVerbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = rewriteImport(verbose)
|
||||
err = rewriteImport(boolVarVerbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tidy(verbose)
|
||||
err = tidy(boolVarVerbose)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if verbose {
|
||||
if boolVarVerbose {
|
||||
console.Success("[OK] refactor finish, execute %q on project root to check status.",
|
||||
"go test -race ./...")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user