1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 05:00:54 +00:00
bee/cmd/commands/update/update.go
王厚伟 adbc0af183 Merge branch 'develop-up' into develop
# Conflicts:
#	README.md
#	cmd/commands/update/update.go
#	cmd/commands/version/banner.go
2020-12-22 22:17:05 +08:00

42 lines
966 B
Go

package update
import (
"flag"
"os"
"os/exec"
"github.com/beego/bee/v2/cmd/commands"
"github.com/beego/bee/v2/config"
beeLogger "github.com/beego/bee/v2/logger"
"github.com/beego/bee/v2/utils"
)
var CmdUpdate = &commands.Command{
UsageLine: "update",
Short: "Update Bee",
Long: `
Automatic run command "go get -u github.com/beego/bee/v2" for selfupdate
`,
Run: updateBee,
}
func init() {
fs := flag.NewFlagSet("update", flag.ContinueOnError)
CmdUpdate.Flag = *fs
commands.AvailableCommands = append(commands.AvailableCommands, CmdUpdate)
}
func updateBee(cmd *commands.Command, args []string) int {
beeLogger.Log.Info("Updating")
beePath := config.GitRemotePath
cmdUp := exec.Command("go", "get", "-u", beePath)
cmdUp.Stdout = os.Stdout
cmdUp.Stderr = os.Stderr
if err := cmdUp.Run(); err != nil {
beeLogger.Log.Warnf("Run cmd err:%s", err)
}
// update the Time when updateBee every time
utils.UpdateLastPublishedTime()
return 0
}