mirror of
https://github.com/beego/bee.git
synced 2025-06-11 18:40:40 +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:
@ -31,6 +31,7 @@ import (
|
||||
_ "github.com/beego/bee/cmd/commands/rs"
|
||||
_ "github.com/beego/bee/cmd/commands/run"
|
||||
_ "github.com/beego/bee/cmd/commands/server"
|
||||
_ "github.com/beego/bee/cmd/commands/update"
|
||||
_ "github.com/beego/bee/cmd/commands/version"
|
||||
"github.com/beego/bee/utils"
|
||||
)
|
||||
|
@ -65,6 +65,7 @@ func (c *Command) Out() io.Writer {
|
||||
if c.output != nil {
|
||||
return *c.output
|
||||
}
|
||||
|
||||
return colors.NewColorWriter(os.Stderr)
|
||||
}
|
||||
|
||||
|
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
|
||||
}
|
@ -14,11 +14,13 @@ import (
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/beego/bee/cmd/commands"
|
||||
"github.com/beego/bee/config"
|
||||
beeLogger "github.com/beego/bee/logger"
|
||||
"github.com/beego/bee/logger/colors"
|
||||
"github.com/beego/bee/utils"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const verboseVersionBanner string = `%s%s______
|
||||
@ -57,7 +59,7 @@ Prints the current Bee, Beego and Go version alongside the platform information.
|
||||
}
|
||||
var outputFormat string
|
||||
|
||||
const version = "1.12.0"
|
||||
const version = config.Version
|
||||
|
||||
func init() {
|
||||
fs := flag.NewFlagSet("version", flag.ContinueOnError)
|
||||
|
Reference in New Issue
Block a user