@@ -10,16 +10,14 @@ import (
10
10
11
11
"github.com/bmatcuk/doublestar/v4"
12
12
"github.com/charmbracelet/log"
13
- "github.com/danawoodman/cng/internal/domain"
14
13
"github.com/fsnotify/fsnotify"
15
14
)
16
15
16
+ // todo: inject logging using WithLogger
17
17
var logger = log .NewWithOptions (os .Stderr , log.Options {
18
18
Prefix : "cng" ,
19
19
})
20
20
21
- // todo: inject logging using WithLogger
22
-
23
21
type WatcherConfig struct {
24
22
ExcludePaths []string
25
23
Command []string
@@ -35,7 +33,7 @@ type Watcher struct {
35
33
cmd * exec.Cmd
36
34
lastCmdStart time.Time
37
35
log func (msg string , args ... interface {})
38
- skipper domain. Skipper
36
+ skipper Skipper
39
37
workDir string
40
38
}
41
39
@@ -53,7 +51,7 @@ func NewWatcher(config WatcherConfig) Watcher {
53
51
config : config ,
54
52
// todo: make this injectable
55
53
workDir : workDir ,
56
- skipper : domain . NewSkipper (workDir , config .Exclude ),
54
+ skipper : NewSkipper (workDir , config .Exclude ),
57
55
log : func (msg string , args ... interface {}) {
58
56
if config .Verbose {
59
57
logger .Info (msg , args ... )
@@ -63,8 +61,6 @@ func NewWatcher(config WatcherConfig) Watcher {
63
61
}
64
62
65
63
func (w Watcher ) Start () {
66
- // fmt.Println("WORKING DIRECTORY:", wd)
67
-
68
64
w .log ("Command to run:" , "cmd" , w .config .Command )
69
65
w .log ("Watched paths:" , "paths" , w .config .ExcludePaths )
70
66
@@ -77,10 +73,7 @@ func (w Watcher) Start() {
77
73
w .log ("Adding watched paths:" , "paths" , w .config .ExcludePaths )
78
74
for _ , pattern := range w .config .ExcludePaths {
79
75
expandedPath := filepath .Join (w .workDir , pattern )
80
- // fmt.Println("EXPANDED PATH:", expandedPath)
81
-
82
76
rootDir , _ := doublestar .SplitPattern (expandedPath )
83
- // fmt.Println("ROOT DIR:", rootDir)
84
77
85
78
if err := watcher .Add (rootDir ); err != nil {
86
79
w .exit ("Could not watch root directory:" , "dir" , rootDir , " error:" , err )
@@ -170,11 +163,6 @@ func (w Watcher) Start() {
170
163
w .kill ()
171
164
}
172
165
173
- // if event.Op&fsnotify.Create == fsnotify.Create || event.Op&fsnotify.Remove == fsnotify.Remove {
174
- // watcher.Remove(event.Name) // Attempt to remove in case it's deleted
175
- // addFiles() // Re-add files to catch any new/removed files
176
- // }
177
-
178
166
w .runCmd ()
179
167
180
168
case <- sig :
0 commit comments