2012-12-15 16:56:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2013-06-26 13:02:05 +00:00
|
|
|
path "path/filepath"
|
2013-07-06 07:30:57 +00:00
|
|
|
"runtime"
|
2012-12-15 16:56:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-07-06 07:30:57 +00:00
|
|
|
var appname string
|
|
|
|
|
2012-12-15 16:56:28 +00:00
|
|
|
func startapp(cmd *Command, args []string) {
|
|
|
|
if len(args) != 1 {
|
|
|
|
fmt.Println("error args")
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
crupath, _ := os.Getwd()
|
2013-07-06 07:30:57 +00:00
|
|
|
Debugf("current path:%s\n", crupath)
|
|
|
|
|
2012-12-15 16:56:28 +00:00
|
|
|
var paths []string
|
|
|
|
paths = append(paths, path.Join(crupath, "controllers"), path.Join(crupath, "models"))
|
|
|
|
NewWatcher(paths)
|
2013-07-06 07:30:57 +00:00
|
|
|
appname = args[0]
|
|
|
|
Autobuild()
|
2012-12-15 16:56:28 +00:00
|
|
|
for {
|
2013-07-06 07:30:57 +00:00
|
|
|
runtime.Gosched()
|
2012-12-15 16:56:28 +00:00
|
|
|
}
|
|
|
|
}
|