2017-03-06 23:58:53 +00:00
|
|
|
package beefix
|
2016-01-06 03:55:56 +00:00
|
|
|
|
2016-01-07 17:20:12 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
2017-03-06 23:58:53 +00:00
|
|
|
|
|
|
|
"github.com/beego/bee/cmd/commands"
|
|
|
|
"github.com/beego/bee/cmd/commands/version"
|
|
|
|
beeLogger "github.com/beego/bee/logger"
|
2020-10-15 13:40:16 +00:00
|
|
|
"github.com/beego/bee/utils"
|
2016-01-07 17:20:12 +00:00
|
|
|
)
|
|
|
|
|
2017-03-06 23:58:53 +00:00
|
|
|
var CmdFix = &commands.Command{
|
2016-01-06 03:55:56 +00:00
|
|
|
UsageLine: "fix",
|
2016-12-03 10:54:41 +00:00
|
|
|
Short: "Fixes your application by making it compatible with newer versions of Beego",
|
2020-10-15 13:40:16 +00:00
|
|
|
Long: `
|
2016-12-03 10:54:41 +00:00
|
|
|
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() {
|
2017-03-06 23:58:53 +00:00
|
|
|
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")
|
2017-03-06 23:58:53 +00:00
|
|
|
commands.AvailableCommands = append(commands.AvailableCommands, CmdFix)
|
2016-01-06 03:55:56 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 23:58:53 +00:00
|
|
|
func runFix(cmd *commands.Command, args []string) int {
|
2020-10-15 13:40:16 +00:00
|
|
|
t := target.String()
|
|
|
|
if t == "" || t == "1.6"{
|
|
|
|
return fixTo16(cmd, args)
|
|
|
|
} else if strings.HasPrefix(t, "2") {
|
|
|
|
// upgrade to v2
|
|
|
|
return fix1To2()
|
2016-01-07 17:20:12 +00:00
|
|
|
}
|
2016-11-13 14:14:48 +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
|
|
|
|
}
|