mirror of
https://github.com/beego/bee.git
synced 2025-06-13 11:50:39 +00:00
add cmd 'bee update' to update self
just notice once a day if there is a new version
This commit is contained in:
38
cmd/commands/update/update.go
Normal file
38
cmd/commands/update/update.go
Normal file
@ -0,0 +1,38 @@
|
||||
package update
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/beego/bee/cmd/commands"
|
||||
"github.com/beego/bee/config"
|
||||
beeLogger "github.com/beego/bee/logger"
|
||||
)
|
||||
|
||||
var CmdUpdate = &commands.Command{
|
||||
UsageLine: "update",
|
||||
Short: "Update Bee",
|
||||
Long: `
|
||||
Automatic run command "go get -u github.com/beego/bee" 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)
|
||||
}
|
||||
return 0
|
||||
}
|
Reference in New Issue
Block a user