From 34dbbd4ac1321a18fd8cf95200b8c7c957f7dcc7 Mon Sep 17 00:00:00 2001 From: Ruslan Abelkharisov Date: Wed, 30 Aug 2023 13:05:31 +0300 Subject: [PATCH] apply fix from https://github.com/githubnemo/CompileDaemon/pull/85 --- daemon.go | 26 +++++++++++++++++--------- go.mod | 1 + go.sum | 2 ++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/daemon.go b/daemon.go index 82f1300..35aec43 100644 --- a/daemon.go +++ b/daemon.go @@ -4,18 +4,18 @@ CompileDaemon is a very simple compile daemon for Go. CompileDaemon watches your .go files in a directory and invokes `go build` if a file changes. -Examples +# Examples In its simplest form, the defaults will do. With the current working directory set to the source directory you can simply… - $ CompileDaemon + $ CompileDaemon … and it will recompile your code whenever you save a source file. If you want it to also run your program each time it builds you might add… - $ CompileDaemon -command="./MyProgram -my-options" + $ CompileDaemon -command="./MyProgram -my-options" … and it will also keep a copy of your program running. Killing the old one and 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… You may find that you need to exclude some directories and files from monitoring, such as a .git repository or emacs temporary files… - $ CompileDaemon -exclude-dir=.git -exclude=".#*" + $ CompileDaemon -exclude-dir=.git -exclude=".#*" If you want to monitor files other than .go and .c files you might… - $ CompileDaemon -include=Makefile -include="*.less" -include="*.tmpl" + $ CompileDaemon -include=Makefile -include="*.less" -include="*.tmpl" -Options +# Options There are command line options. @@ -61,7 +61,6 @@ There are command line options. ACTIONS -build=CCC – Execute CCC to rebuild when a file changes -command=CCC – Run command CCC after a successful build, stops previous command first - */ package main @@ -69,6 +68,7 @@ import ( "bufio" "flag" "fmt" + "github.com/kballard/go-shellquote" "io" "log" "os" @@ -178,7 +178,11 @@ func build() bool { func runBuildCommand(c string) error { c = strings.TrimSpace(c) - args := strings.Split(c, " ") + args, err := shellquote.Split(c) + if err != nil { + log.Println(failColor("Error while splitting build command:\n"), err) + return err + } if len(args) == 0 { return nil } @@ -257,7 +261,11 @@ func logger(pipeChan <-chan io.ReadCloser) { // Start the supplied command and return stdout and stderr pipes for logging. func startCommand(command string) (cmd *exec.Cmd, stdout io.ReadCloser, stderr io.ReadCloser, err error) { - args := strings.Split(command, " ") + args, err := shellquote.Split(command) + if err != nil { + log.Println(failColor("Error while splitting start command:\n"), err) + return + } cmd = exec.Command(args[0], args[1:]...) if *flagRunDir != "" { diff --git a/go.mod b/go.mod index 2fa6912..0da39ad 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,6 @@ go 1.16 require ( github.com/fatih/color v1.9.0 github.com/fsnotify/fsnotify v1.4.9 + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/radovskyb/watcher v1.0.7 ) diff --git a/go.sum b/go.sum index 897f9de..5212162 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=