@@ -4,18 +4,18 @@ CompileDaemon is a very simple compile daemon for Go.
44CompileDaemon watches your .go files in a directory and invokes `go build`
55if a file changes.
66
7- Examples
7+ # Examples
88
99In its simplest form, the defaults will do. With the current working directory set
1010to the source directory you can simply…
1111
12- $ CompileDaemon
12+ $ CompileDaemon
1313
1414… and it will recompile your code whenever you save a source file.
1515
1616If you want it to also run your program each time it builds you might add…
1717
18- $ CompileDaemon -command="./MyProgram -my-options"
18+ $ CompileDaemon -command="./MyProgram -my-options"
1919
2020… and it will also keep a copy of your program running. Killing the old one and
2121starting a new one each time you build. For advanced usage you can also supply
@@ -28,13 +28,13 @@ the changed file to the command by doing…
2828You may find that you need to exclude some directories and files from
2929monitoring, such as a .git repository or emacs temporary files…
3030
31- $ CompileDaemon -exclude-dir=.git -exclude=".#*"
31+ $ CompileDaemon -exclude-dir=.git -exclude=".#*"
3232
3333If you want to monitor files other than .go and .c files you might…
3434
35- $ CompileDaemon -include=Makefile -include="*.less" -include="*.tmpl"
35+ $ CompileDaemon -include=Makefile -include="*.less" -include="*.tmpl"
3636
37- Options
37+ # Options
3838
3939There are command line options.
4040
@@ -61,14 +61,14 @@ There are command line options.
6161 ACTIONS
6262 -build=CCC – Execute CCC to rebuild when a file changes
6363 -command=CCC – Run command CCC after a successful build, stops previous command first
64-
6564*/
6665package main
6766
6867import (
6968 "bufio"
7069 "flag"
7170 "fmt"
71+ "github.com/kballard/go-shellquote"
7272 "io"
7373 "log"
7474 "os"
@@ -178,7 +178,11 @@ func build() bool {
178178
179179func runBuildCommand (c string ) error {
180180 c = strings .TrimSpace (c )
181- args := strings .Split (c , " " )
181+ args , err := shellquote .Split (c )
182+ if err != nil {
183+ log .Println (failColor ("Error while splitting build command:\n " ), err )
184+ return err
185+ }
182186 if len (args ) == 0 {
183187 return nil
184188 }
@@ -257,7 +261,11 @@ func logger(pipeChan <-chan io.ReadCloser) {
257261
258262// Start the supplied command and return stdout and stderr pipes for logging.
259263func startCommand (command string ) (cmd * exec.Cmd , stdout io.ReadCloser , stderr io.ReadCloser , err error ) {
260- args := strings .Split (command , " " )
264+ args , err := shellquote .Split (command )
265+ if err != nil {
266+ log .Println (failColor ("Error while splitting start command:\n " ), err )
267+ return
268+ }
261269 cmd = exec .Command (args [0 ], args [1 :]... )
262270
263271 if * flagRunDir != "" {
0 commit comments