Skip to content

Commit aec214f

Browse files
authored
Merge pull request #2192 from FabianKramm/print-feat
feat: add --exclude to run_watch
2 parents ebbfc48 + 29797e3 commit aec214f

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

  • pkg/devspace/pipeline/engine/basichandler/commands

pkg/devspace/pipeline/engine/basichandler/commands/run_watch.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import (
2121
type RunWatchOptions struct {
2222
FailOnError bool `long:"fail-on-error" description:"If true the command will fail on an error while running the sub command"`
2323

24-
SkipInitial bool `long:"skip-initial" description:"If true will not execute the command immediately."`
25-
Silent bool `long:"silent" description:"If true will not print any warning about restarting the command."`
26-
Paths []string `long:"path" short:"p" description:"The paths to watch. Can be patterns in the form of ./**/my-file.txt"`
24+
SkipInitial bool `long:"skip-initial" description:"If true will not execute the command immediately."`
25+
Silent bool `long:"silent" description:"If true will not print any warning about restarting the command."`
26+
SkipAndSilent bool `long:"skip-and-silent" short:"s" description:"If enabled will not print when the command is restarted and not execute the command initially."`
27+
Exclude []string `long:"exclude" short:"e" description:"The paths to ignore. Can be patterns in the form of ./**/my-file.txt"`
28+
Paths []string `long:"path" short:"p" description:"The paths to watch. Can be patterns in the form of ./**/my-file.txt"`
2729
}
2830

2931
func RunWatch(ctx context.Context, args []string, handler types2.ExecHandler, log log.Logger) error {
@@ -53,6 +55,10 @@ type watcher struct {
5355

5456
func (w *watcher) Watch(ctx context.Context, action func(ctx context.Context) error, log log.Logger) error {
5557
patterns := w.options.Paths
58+
if w.options.SkipAndSilent {
59+
w.options.Silent = true
60+
w.options.SkipInitial = true
61+
}
5662

5763
// prepare patterns
5864
for i, p := range patterns {
@@ -163,15 +169,29 @@ func (w *watcher) handleCommand(ctx context.Context, patterns []string, action f
163169
return nil
164170
case e := <-events:
165171
// check if match
172+
hasMatched := false
166173
for _, p := range patterns {
167-
hasMatched, _ := doublestar.Match(p, e)
174+
hasMatched, _ = doublestar.Match(p, e)
168175
if hasMatched {
176+
break
177+
}
178+
}
179+
180+
if hasMatched {
181+
excluded := false
182+
for _, excludePath := range w.options.Exclude {
183+
excluded, _ = doublestar.Match(excludePath, e)
184+
if excluded {
185+
break
186+
}
187+
}
188+
189+
if !excluded {
169190
numEvents++
170191
lastChange = e
171-
break
172192
}
173193
}
174-
case <-time.After(time.Second * 2):
194+
case <-time.After(time.Millisecond * 1200):
175195
if numEvents > 0 {
176196
// kill application and wait for exit
177197
if !w.options.Silent {

0 commit comments

Comments
 (0)