Skip to content

Commit

Permalink
apply fix from githubnemo#85
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Abelkharisov committed Aug 30, 2023
1 parent 8b56669 commit 34dbbd4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
26 changes: 17 additions & 9 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -61,14 +61,14 @@ 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

import (
"bufio"
"flag"
"fmt"
"github.com/kballard/go-shellquote"
"io"
"log"
"os"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 != "" {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 34dbbd4

Please sign in to comment.