You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: run_watch.go
    path of file: ./repos/devspace/pkg/devspace/pipeline/engine/basichandler/commands
    
    the code of the file until where you have to start completion: package commands

import (
	"context"
	"fmt"
	"os"
	"path/filepath"
	"strings"
	"time"

	"github.com/bmatcuk/doublestar"
	"github.com/jessevdk/go-flags"
	types2 "github.com/loft-sh/devspace/pkg/devspace/pipeline/engine/types"
	"github.com/loft-sh/devspace/pkg/util/log"
	"github.com/loft-sh/devspace/pkg/util/tomb"
	"github.com/loft-sh/notify"
	"github.com/mgutz/ansi"
	"github.com/pkg/errors"
	"mvdan.cc/sh/v3/interp"
)

type RunWatchOptions struct {
	FailOnError bool `long:"fail-on-error" description:"If true the command will fail on an error while running the sub command"`

	SkipInitial   bool     `long:"skip
    
func (w *watcher) handleCommand(ctx context.Context, patterns []string, excludes []string, action func(ctx context.Context) error, events chan string) error {
	hc := interp.HandlerCtx(ctx)
	var t *tomb.Tomb
	if !w.options.SkipInitial {
		t = w.startCommand(ctx, action)
	} else {
		t = &tomb.Tomb{}
		t.Go(func() error { return nil })
	}
	numEvents := 0
	lastChange := ""
	for {
		select {
		case <-ctx.Done():
			t.Kill(nil)
			<-t.Dead()
			return nil
		case e := <-events:
			// check if match
			hasMatched := false
			for _, p := range patterns {
				hasMatched, _ = doublestar.Match(p, e)
				if hasMatched {
					break
				}
			}

			if hasMatched {
				excluded := false
				for _, excludePath := range excludes {
					excluded, _ = doublestar.Match(excludePath, e)
					if excluded {
						break
					}
				}

				if !excluded {
					numEvents++
					lastChange = e
				}
			}
		case <-time.After(time.Millisecond * 1200):
			if numEvents > 0 {
				// kill application and wait for exit
				if !w.options.Silent {
					_, _ = hc.Stderr.Write([]byte(fmt.Sprintf("\n%s Restarting command because '%s' has changed...\n\n", ansi.Color("warn", "red+b"), lastChange)))
				}
				t.Kill(nil)
				select {
				case <-ctx.Done():
					return nil
				case <-t.Dead():
				}

				// restart the command
				t = w.startCommand(ctx, action)
				numEvents = 0
				lastChange = ""
			}
		}

		// check if terminated
		if w.options.FailOnError && t.Terminated() && t.Err() != nil {
			return t.Err()
		}
	}
}