@@ -107,7 +107,6 @@ func (g *globList) Matches(value string) bool {
107107}
108108
109109var (
110- flagDirectory = flag .String ("directory" , "." , "Directory to watch for changes" )
111110 flagPattern = flag .String ("pattern" , FilePattern , "Pattern of watched files" )
112111 flagCommand = flag .String ("command" , "" , "Command to run and restart after build" )
113112 flagCommandStop = flag .Bool ("command-stop" , false , "Stop command before building" )
@@ -122,6 +121,7 @@ var (
122121 flagVerbose = flag .Bool ("verbose" , false , "Be verbose about which directories are watched." )
123122
124123 // initialized in main() due to custom type.
124+ flagDirectories globList
125125 flagExcludedDirs globList
126126 flagExcludedFiles globList
127127 flagIncludedFiles globList
@@ -157,8 +157,8 @@ func build() bool {
157157
158158 if * flagBuildDir != "" {
159159 cmd .Dir = * flagBuildDir
160- } else {
161- cmd .Dir = * flagDirectory
160+ } else if len ( flagDirectories ) > 0 {
161+ cmd .Dir = flagDirectories [ 0 ]
162162 }
163163
164164 output , err := cmd .CombinedOutput ()
@@ -367,19 +367,19 @@ func flusher(buildStarted <-chan string, buildSuccess <-chan bool) {
367367}
368368
369369func main () {
370- flag .Var (& flagExcludedDirs , "exclude-dir" , " Don't watch directories matching this name" )
371- flag .Var (& flagExcludedFiles , "exclude" , " Don't watch files matching this name" )
372- flag .Var (& flagIncludedFiles , "include" , " Watch files matching this name" )
370+ flag .Var (& flagDirectories , "directory" , "Directory to watch for changes, can be set more than once" )
371+ flag .Var (& flagExcludedDirs , "exclude-dir" , " Don't watch directories matching this name, can be set more than once" )
372+ flag .Var (& flagExcludedFiles , "exclude" , " Don't watch files matching this name, can be set more than once" )
373+ flag .Var (& flagIncludedFiles , "include" , " Watch files matching this name, can be set more than once" )
373374
374375 flag .Parse ()
375376
376377 if ! * flagLogPrefix {
377378 log .SetFlags (0 )
378379 }
379380
380- if * flagDirectory == "" {
381- fmt .Fprintf (os .Stderr , "-directory=... is required.\n " )
382- os .Exit (1 )
381+ if len (flagDirectories ) == 0 {
382+ log .Fatal ("-directory must be specified at least once." )
383383 }
384384
385385 if * flagGracefulKill && ! gracefulTerminationPossible () {
@@ -394,32 +394,33 @@ func main() {
394394
395395 defer watcher .Close ()
396396
397- if * flagRecursive == true {
398- err = filepath .Walk (* flagDirectory , func (path string , info os.FileInfo , err error ) error {
399- if err == nil && info .IsDir () {
400- if flagExcludedDirs .Matches (path ) {
401- return filepath .SkipDir
402- } else {
403- if * flagVerbose {
404- log .Printf ("Watching directory '%s' for changes.\n " , path )
397+ for _ , flagDirectory := range flagDirectories {
398+ if * flagRecursive == true {
399+ err = filepath .Walk (flagDirectory , func (path string , info os.FileInfo , err error ) error {
400+ if err == nil && info .IsDir () {
401+ if flagExcludedDirs .Matches (path ) {
402+ return filepath .SkipDir
403+ } else {
404+ if * flagVerbose {
405+ log .Printf ("Watching directory '%s' for changes.\n " , path )
406+ }
407+ return watcher .Add (path )
405408 }
406- return watcher .Add (path )
407409 }
408- }
409- return err
410- })
411-
412- if err != nil {
413- log .Fatal ("filepath.Walk():" , err )
414- }
410+ return err
411+ })
415412
416- if err := watcher . Add ( * flagDirectory ); err != nil {
417- log .Fatal ("watcher.Add ():" , err )
418- }
413+ if err != nil {
414+ log .Fatal ("filepath.Walk ():" , err )
415+ }
419416
420- } else {
421- if err := watcher .Add (* flagDirectory ); err != nil {
422- log .Fatal ("watcher.Add():" , err )
417+ if err := watcher .Add (flagDirectory ); err != nil {
418+ log .Fatal ("watcher.Add():" , err )
419+ }
420+ } else {
421+ if err := watcher .Add (flagDirectory ); err != nil {
422+ log .Fatal ("watcher.Add():" , err )
423+ }
423424 }
424425 }
425426
0 commit comments