Exemplo n.º 1
0
func (command *WatchCmd) Execute(context *console.Context) error {
	command.isDebug = false
	command.context = context
	if len(context.Args) <= 2 {
		return fmt.Errorf("usage: %s watch [command]", context.ExecutionName)
	}
	var err error
	command.wd, err = os.Getwd()
	if err != nil {
		return err
	}
	runner, err := fsnotify.NewRunner(10000)
	if err != nil {
		return err
	}
	runner.Watcher.ErrorHandler = func(err error) {
		fmt.Println("watcher.Error error: ", err)
	}
	runner.Watcher.WatchRecursion(command.wd)
	// wait forever
	runner.Run(func() {
		err := command.restart()
		if err != nil {
			fmt.Println("command.restart() error: ", err)
		}
	})
	return nil
}
Exemplo n.º 2
0
func (command *GoWatch) Execute(context *console.Context) (err error) {
	command.isDebug = false
	command.context = context
	if len(context.Args) != 3 {
		return fmt.Errorf("usage: %s watch [packages]", context.ExecutionName)
	}
	command.mainFilePath = context.Args[2]
	kmgc, err := kmgConfig.LoadEnvFromWd()
	if err != nil {
		return
	}
	command.GOPATH = kmgc.GOPATHToString()
	command.wd = kmgc.ProjectPath
	runner, err := fsnotify.NewRunner(10000)
	if err != nil {
		return err
	}
	runner.Watcher.ErrorHandler = func(err error) {
		fmt.Println("watcher.Error error: ", err)
	}
	runner.Watcher.IsIgnorePath = func(path string) bool {
		if fsnotify.DefaultIsIgnorePath(path) {
			return true
		}
		if path == command.targetFilePath {
			return true
		}
		return false
	}
	runner.Watcher.WatchRecursion(command.wd)
	// wait forever
	runner.Run(func() {
		err := command.restart()
		if err != nil {
			fmt.Println("command.restart() error: ", err)
		}
	})
	return nil
}