Skip to content

Commit 4debdba

Browse files
authored
Merge pull request #83 from francoishill/patch-1
Add cmd line arg to exclude directories from watch
2 parents b22c90d + e926997 commit 4debdba

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func main() {
5353
Value: ".",
5454
Usage: "Path to watch files from",
5555
},
56+
cli.StringSliceFlag{
57+
Name: "excludeDir,x",
58+
Value: &cli.StringSlice{},
59+
Usage: "Relative directories to exclude",
60+
},
5661
cli.BoolFlag{
5762
Name: "immediate,i",
5863
Usage: "run the server immediately after it's built",
@@ -119,7 +124,7 @@ func MainAction(c *cli.Context) {
119124
build(builder, runner, logger)
120125

121126
// scan for changes
122-
scanChanges(c.GlobalString("path"), func(path string) {
127+
scanChanges(c.GlobalString("path"), c.GlobalStringSlice("excludeDir"), func(path string) {
123128
runner.Kill()
124129
build(builder, runner, logger)
125130
})
@@ -160,12 +165,17 @@ func build(builder gin.Builder, runner gin.Runner, logger *log.Logger) {
160165

161166
type scanCallback func(path string)
162167

163-
func scanChanges(watchPath string, cb scanCallback) {
168+
func scanChanges(watchPath string, excludeDirs []string, cb scanCallback) {
164169
for {
165170
filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {
166171
if path == ".git" {
167172
return filepath.SkipDir
168173
}
174+
for _, x := range excludeDirs {
175+
if x == path {
176+
return filepath.SkipDir
177+
}
178+
}
169179

170180
// ignore hidden files
171181
if filepath.Base(path)[0] == '.' {

0 commit comments

Comments
 (0)