Skip to content

Commit 34dbbd4

Browse files
author
Ruslan Abelkharisov
committed
apply fix from githubnemo#85
1 parent 8b56669 commit 34dbbd4

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

daemon.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ CompileDaemon is a very simple compile daemon for Go.
44
CompileDaemon watches your .go files in a directory and invokes `go build`
55
if a file changes.
66
7-
Examples
7+
# Examples
88
99
In its simplest form, the defaults will do. With the current working directory set
1010
to 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
1616
If 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
2121
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…
2828
You may find that you need to exclude some directories and files from
2929
monitoring, such as a .git repository or emacs temporary files…
3030
31-
$ CompileDaemon -exclude-dir=.git -exclude=".#*"
31+
$ CompileDaemon -exclude-dir=.git -exclude=".#*"
3232
3333
If 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
3939
There 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
*/
6665
package main
6766

6867
import (
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

179179
func 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.
259263
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+
}
261269
cmd = exec.Command(args[0], args[1:]...)
262270

263271
if *flagRunDir != "" {

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ go 1.16
55
require (
66
github.com/fatih/color v1.9.0
77
github.com/fsnotify/fsnotify v1.4.9
8+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
89
github.com/radovskyb/watcher v1.0.7
910
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
22
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
33
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
44
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
5+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
6+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
57
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
68
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
79
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=

0 commit comments

Comments
 (0)