@@ -4,18 +4,18 @@ CompileDaemon is a very simple compile daemon for Go.
4
4
CompileDaemon watches your .go files in a directory and invokes `go build`
5
5
if a file changes.
6
6
7
- Examples
7
+ # Examples
8
8
9
9
In its simplest form, the defaults will do. With the current working directory set
10
10
to the source directory you can simply…
11
11
12
- $ CompileDaemon
12
+ $ CompileDaemon
13
13
14
14
… and it will recompile your code whenever you save a source file.
15
15
16
16
If you want it to also run your program each time it builds you might add…
17
17
18
- $ CompileDaemon -command="./MyProgram -my-options"
18
+ $ CompileDaemon -command="./MyProgram -my-options"
19
19
20
20
… and it will also keep a copy of your program running. Killing the old one and
21
21
starting 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…
28
28
You may find that you need to exclude some directories and files from
29
29
monitoring, such as a .git repository or emacs temporary files…
30
30
31
- $ CompileDaemon -exclude-dir=.git -exclude=".#*"
31
+ $ CompileDaemon -exclude-dir=.git -exclude=".#*"
32
32
33
33
If you want to monitor files other than .go and .c files you might…
34
34
35
- $ CompileDaemon -include=Makefile -include="*.less" -include="*.tmpl"
35
+ $ CompileDaemon -include=Makefile -include="*.less" -include="*.tmpl"
36
36
37
- Options
37
+ # Options
38
38
39
39
There are command line options.
40
40
@@ -61,14 +61,14 @@ There are command line options.
61
61
ACTIONS
62
62
-build=CCC – Execute CCC to rebuild when a file changes
63
63
-command=CCC – Run command CCC after a successful build, stops previous command first
64
-
65
64
*/
66
65
package main
67
66
68
67
import (
69
68
"bufio"
70
69
"flag"
71
70
"fmt"
71
+ "github.com/kballard/go-shellquote"
72
72
"io"
73
73
"log"
74
74
"os"
@@ -178,7 +178,11 @@ func build() bool {
178
178
179
179
func runBuildCommand (c string ) error {
180
180
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
+ }
182
186
if len (args ) == 0 {
183
187
return nil
184
188
}
@@ -257,7 +261,11 @@ func logger(pipeChan <-chan io.ReadCloser) {
257
261
258
262
// Start the supplied command and return stdout and stderr pipes for logging.
259
263
func 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
+ }
261
269
cmd = exec .Command (args [0 ], args [1 :]... )
262
270
263
271
if * flagRunDir != "" {
0 commit comments