1
0
mirror of https://github.com/beego/bee.git synced 2024-11-23 22:10:54 +00:00
bee/cmd/commands/beefix/fix.go

49 lines
1.2 KiB
Go
Raw Normal View History

package beefix
2016-01-06 03:55:56 +00:00
2016-01-07 17:20:12 +00:00
import (
"strings"
2020-12-16 05:20:41 +00:00
"github.com/beego/bee/v2/cmd/commands"
"github.com/beego/bee/v2/cmd/commands/version"
beeLogger "github.com/beego/bee/v2/logger"
"github.com/beego/bee/v2/utils"
2016-01-07 17:20:12 +00:00
)
var CmdFix = &commands.Command{
2016-01-06 03:55:56 +00:00
UsageLine: "fix",
Short: "Fixes your application by making it compatible with newer versions of Beego",
2020-10-15 13:40:16 +00:00
Long: `
The command 'fix' will try to solve those issues by upgrading your code base
2020-10-15 13:40:16 +00:00
to be compatible with Beego old version
-s source version
-t target version
example: bee fix -s 1 -t 2 means that upgrade Beego version from v1.x to v2.x
2016-01-06 03:55:56 +00:00
`,
}
2020-10-15 13:40:16 +00:00
var (
source, target utils.DocValue
)
2016-01-06 03:55:56 +00:00
func init() {
CmdFix.Run = runFix
CmdFix.PreRun = func(cmd *commands.Command, args []string) { version.ShowShortVersionBanner() }
2020-10-15 13:40:16 +00:00
CmdFix.Flag.Var(&source, "s", "source version")
CmdFix.Flag.Var(&target, "t", "target version")
commands.AvailableCommands = append(commands.AvailableCommands, CmdFix)
2016-01-06 03:55:56 +00:00
}
func runFix(cmd *commands.Command, args []string) int {
2020-10-15 13:40:16 +00:00
t := target.String()
2020-12-16 05:20:41 +00:00
if t == "" || t == "1.6" {
2020-10-15 13:40:16 +00:00
return fixTo16(cmd, args)
} else if strings.HasPrefix(t, "2") {
// upgrade to v2
return fix1To2()
2016-01-07 17:20:12 +00:00
}
2020-10-15 13:40:16 +00:00
beeLogger.Log.Info("The target is compatible version, do nothing")
2016-01-06 03:55:56 +00:00
return 0
}