@@ -30,6 +30,15 @@ type RunWatchOptions struct {
3030}
3131
3232func RunWatch (ctx context.Context , args []string , handler types2.ExecHandler , log log.Logger ) error {
33+ command := []string {}
34+
35+ // Separately handle the `--` catchall flag
36+ // in order to have clean arguments for the parsing below
37+ commandINdex := indexOf ("--" , args )
38+ if commandINdex > 0 {
39+ command = args [commandINdex + 1 :]
40+ }
41+
3342 options := & RunWatchOptions {}
3443 args , err := flags .ParseArgs (options , args )
3544 if err != nil {
@@ -41,10 +50,15 @@ func RunWatch(ctx context.Context, args []string, handler types2.ExecHandler, lo
4150 if len (args ) == 0 {
4251 return fmt .Errorf ("usage: run_watch --path MY_PATH -- my_command" )
4352 }
53+ if len (args ) > len (command ) {
54+ // if we have more args left thant the one after "--" then we have some invalid flags inside
55+ return fmt .Errorf ("invalid flags: %v, usage: run_watch --path MY_PATH --path 'MY/**/GLOB*/PATH' -- my_command" , command )
56+ }
4457
4558 w := & watcher {
4659 options : * options ,
4760 }
61+
4862 return w .Watch (ctx , func (ctx context.Context ) error {
4963 return handler .ExecHandler (ctx , args )
5064 }, log )
@@ -232,3 +246,12 @@ func (w *watcher) startCommand(ctx context.Context, action func(ctx context.Cont
232246 })
233247 return t
234248}
249+
250+ func indexOf (element string , data []string ) int {
251+ for k , v := range data {
252+ if element == v {
253+ return k
254+ }
255+ }
256+ return - 1
257+ }
0 commit comments