@@ -107,7 +107,6 @@ func (g *globList) Matches(value string) bool {
107
107
}
108
108
109
109
var (
110
- flagDirectory = flag .String ("directory" , "." , "Directory to watch for changes" )
111
110
flagPattern = flag .String ("pattern" , FilePattern , "Pattern of watched files" )
112
111
flagCommand = flag .String ("command" , "" , "Command to run and restart after build" )
113
112
flagCommandStop = flag .Bool ("command-stop" , false , "Stop command before building" )
@@ -122,6 +121,7 @@ var (
122
121
flagVerbose = flag .Bool ("verbose" , false , "Be verbose about which directories are watched." )
123
122
124
123
// initialized in main() due to custom type.
124
+ flagDirectories globList
125
125
flagExcludedDirs globList
126
126
flagExcludedFiles globList
127
127
flagIncludedFiles globList
@@ -157,8 +157,8 @@ func build() bool {
157
157
158
158
if * flagBuildDir != "" {
159
159
cmd .Dir = * flagBuildDir
160
- } else {
161
- cmd .Dir = * flagDirectory
160
+ } else if len ( flagDirectories ) > 0 {
161
+ cmd .Dir = flagDirectories [ 0 ]
162
162
}
163
163
164
164
output , err := cmd .CombinedOutput ()
@@ -367,19 +367,19 @@ func flusher(buildStarted <-chan string, buildSuccess <-chan bool) {
367
367
}
368
368
369
369
func 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" )
373
374
374
375
flag .Parse ()
375
376
376
377
if ! * flagLogPrefix {
377
378
log .SetFlags (0 )
378
379
}
379
380
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." )
383
383
}
384
384
385
385
if * flagGracefulKill && ! gracefulTerminationPossible () {
@@ -394,32 +394,33 @@ func main() {
394
394
395
395
defer watcher .Close ()
396
396
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 )
405
408
}
406
- return watcher .Add (path )
407
409
}
408
- }
409
- return err
410
- })
411
-
412
- if err != nil {
413
- log .Fatal ("filepath.Walk():" , err )
414
- }
410
+ return err
411
+ })
415
412
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
+ }
419
416
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
+ }
423
424
}
424
425
}
425
426
0 commit comments