1
0
mirror of https://github.com/beego/bee.git synced 2025-01-11 08:27:13 +00:00

49 lines
1.2 KiB
Go
Raw Normal View History

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