From abf543d51e701409c61de7bb0334e9b015b953f7 Mon Sep 17 00:00:00 2001 From: Lachlan Donald Date: Sat, 15 Apr 2017 12:58:50 +1000 Subject: [PATCH 1/4] Support a --bin argument for path to binary --- rerun.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rerun.go b/rerun.go index a82ecb3..67a5aed 100644 --- a/rerun.go +++ b/rerun.go @@ -9,18 +9,20 @@ import ( "errors" "flag" "fmt" - "github.com/howeyc/fsnotify" "go/build" "log" "os" "os/exec" "path" "path/filepath" + + "github.com/howeyc/fsnotify" ) var ( do_tests = flag.Bool("test", false, "Run tests (before running program)") do_build = flag.Bool("build", false, "Build program") + build_bin = flag.String("bin", "", "Provide a specific path for the build binary") never_run = flag.Bool("no-run", false, "Do not run") race_detector = flag.Bool("race", false, "Run program and tests with the race detector") ) @@ -83,11 +85,16 @@ func test(buildpath string) (passed bool, err error) { } func gobuild(buildpath string) (passed bool, err error) { - cmdline := []string{"go", "build"} + cmdline := []string{"go", "build", "-i"} if *race_detector { cmdline = append(cmdline, "-race") } + + if *build_bin != "" { + cmdline = append(cmdline, "-o", *build_bin) + } + cmdline = append(cmdline, "-v", buildpath) // setup the build command, use a shared buffer for both stdOut and stdErr From 889244395e06da9432347c242009869d67ad7ea5 Mon Sep 17 00:00:00 2001 From: Adhi Hargo Date: Mon, 25 Sep 2017 23:38:33 +0700 Subject: [PATCH 2/4] Use more descriptive help message and library-supported way to print it. --- rerun.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rerun.go b/rerun.go index 67a5aed..8bcb2dc 100644 --- a/rerun.go +++ b/rerun.go @@ -279,10 +279,15 @@ func rerun(buildpath string, args []string) (err error) { } func main() { + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS] IMPORT_PATH [ARGS]\nOptions:\n", os.Args[0]) + flag.PrintDefaults() + } flag.Parse() if len(flag.Args()) < 1 { - log.Fatal("Usage: rerun [--test] [--no-run] [--build] [--race] [arg]*") + flag.Usage() + os.Exit(1) } buildpath := flag.Args()[0] From 472743928864d0c496dc1c178fbce8f744faf567 Mon Sep 17 00:00:00 2001 From: Adhi Hargo Date: Tue, 26 Sep 2017 04:51:47 +0700 Subject: [PATCH 3/4] Add -ignore option, accepting regexp of filenames to ignore. Fixes #15 Some tools create temp files that rerun won't ignore if relying only on extension (e.g. on editing X.go emacs creates .#X.go). --- rerun.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rerun.go b/rerun.go index 8bcb2dc..109e32f 100644 --- a/rerun.go +++ b/rerun.go @@ -15,6 +15,7 @@ import ( "os/exec" "path" "path/filepath" + "regexp" "github.com/howeyc/fsnotify" ) @@ -22,9 +23,10 @@ import ( var ( do_tests = flag.Bool("test", false, "Run tests (before running program)") do_build = flag.Bool("build", false, "Build program") - build_bin = flag.String("bin", "", "Provide a specific path for the build binary") never_run = flag.Bool("no-run", false, "Do not run") race_detector = flag.Bool("race", false, "Run program and tests with the race detector") + build_bin = flag.String("bin", "", "Provide a specific path for the build binary") + ignore_re_str = flag.String("ignore", "", "Regexp pattern of filenames to ignore") ) func install(buildpath, lastError string) (installed bool, errorOutput string, err error) { @@ -219,11 +221,18 @@ func rerun(buildpath string, args []string) (err error) { return } + // construct regexp obj, unused on error (assuming Compile returns nil if so). + var ignoreRe *regexp.Regexp + ignoreRe, err = regexp.Compile(*ignore_re_str) + if err != nil { + log.Print(err) + } for { // read event from the watcher we, _ := <-watcher.Event // other files in the directory don't count - we watch the whole thing in case new .go files appear. - if filepath.Ext(we.Name) != ".go" { + if fn := filepath.Base(we.Name) ; + (ignoreRe != nil && ignoreRe.FindString(fn) != "") || filepath.Ext(fn) != ".go" { continue } From 759a5d92f348d91c566a8d4858d8ff3214d53aa0 Mon Sep 17 00:00:00 2001 From: Adhi Hargo Date: Wed, 27 Sep 2017 02:36:15 +0700 Subject: [PATCH 4/4] Applied gofmt --- rerun.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rerun.go b/rerun.go index 109e32f..66b8610 100644 --- a/rerun.go +++ b/rerun.go @@ -231,8 +231,7 @@ func rerun(buildpath string, args []string) (err error) { // read event from the watcher we, _ := <-watcher.Event // other files in the directory don't count - we watch the whole thing in case new .go files appear. - if fn := filepath.Base(we.Name) ; - (ignoreRe != nil && ignoreRe.FindString(fn) != "") || filepath.Ext(fn) != ".go" { + if fn := filepath.Base(we.Name); (ignoreRe != nil && ignoreRe.FindString(fn) != "") || filepath.Ext(fn) != ".go" { continue }