mirror of
https://github.com/beego/bee.git
synced 2024-11-24 08:30:53 +00:00
54 lines
968 B
Go
54 lines
968 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
var cmdStart = &Command{
|
|
UsageLine: "start [appname]",
|
|
Short: "start the app which can hot compile",
|
|
Long: `
|
|
start the appname throw exec.Command
|
|
|
|
then start a inotify watch for current dir
|
|
|
|
when the file has changed bee will auto go build and restart the app
|
|
|
|
file changed
|
|
|
|
|
checked is go file
|
|
|
|
|
yes no
|
|
| |
|
|
go build do nothing
|
|
|
|
|
restart app
|
|
`,
|
|
}
|
|
|
|
func init() {
|
|
cmdStart.Run = startapp
|
|
}
|
|
|
|
func startapp(cmd *Command, args []string) {
|
|
if len(args) != 1 {
|
|
fmt.Println("error args")
|
|
os.Exit(2)
|
|
}
|
|
crupath, _ := os.Getwd()
|
|
var paths []string
|
|
paths = append(paths, path.Join(crupath, "controllers"), path.Join(crupath, "models"))
|
|
NewWatcher(paths)
|
|
go Start(args[0])
|
|
for {
|
|
select {
|
|
case <-restart:
|
|
go Start(args[0])
|
|
case <-builderror:
|
|
fmt.Println("build error:", builderror)
|
|
}
|
|
}
|
|
}
|