forked from astaxie/bee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.go
53 lines (46 loc) · 968 Bytes
/
start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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)
}
}
}