1
0
mirror of https://github.com/beego/bee.git synced 2024-12-26 01:10:50 +00:00
bee/cmd/commands/beefix/fix1To2.go

62 lines
1.8 KiB
Go
Raw Normal View History

2020-12-16 05:20:41 +00:00
// Copyright 2020
2020-10-15 13:40:16 +00:00
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package beefix
import (
"os"
"os/exec"
2020-12-16 05:20:41 +00:00
beeLogger "github.com/beego/bee/v2/logger"
2020-10-15 13:40:16 +00:00
)
func fix1To2() int {
beeLogger.Log.Info("Upgrading the application...")
2021-08-05 10:31:53 +00:00
cmdStr := `go get -u github.com/beego/beego/v2@master`
2020-10-15 13:40:16 +00:00
err := runShell(cmdStr)
if err != nil {
2020-12-16 05:20:41 +00:00
beeLogger.Log.Error(err.Error())
beeLogger.Log.Error(`fetch v2.0.1 failed. Please try to run: export GO111MODULE=on
and if your network is not stable, please try to use proxy, for example: export GOPROXY=https://goproxy.cn;'
`)
return 1
}
cmdStr = `find ./ -name '*.go' -type f -exec sed -i '' -e 's/github.com\/astaxie\/beego/github.com\/beego\/beego\/v2\/adapter/g' {} \;`
err = runShell(cmdStr)
if err != nil {
beeLogger.Log.Error(err.Error())
2020-10-15 13:40:16 +00:00
return 1
}
2020-12-14 08:25:27 +00:00
cmdStr = `find ./ -name '*.go' -type f -exec sed -i '' -e 's/"github.com\/beego\/beego\/v2\/adapter"/beego "github.com\/beego\/beego\/v2\/adapter"/g' {} \;`
2020-10-15 13:40:16 +00:00
err = runShell(cmdStr)
if err != nil {
2020-12-16 05:20:41 +00:00
beeLogger.Log.Error(err.Error())
2020-10-15 13:40:16 +00:00
return 1
}
return 0
}
func runShell(cmdStr string) error {
c := exec.Command("sh", "-c", cmdStr)
c.Stdout = os.Stdout
err := c.Run()
if err != nil {
beeLogger.Log.Errorf("execute command [%s] failed: %s", cmdStr, err.Error())
return err
}
return nil
2020-12-13 16:44:48 +00:00
}