Esempio n. 1
0
func main() {
	var err error

	flag.Parse()
	dotenv.Load()
	signal.Notify(done, os.Interrupt, os.Kill)

	cmd, err = cmdtmpl.NewCommand(flag.Args())
	if err != nil {
		log.Println("error when parsing command")
		log.Fatal(err)
	}

	dir, err := os.Getwd()
	if err != nil {
		log.Println("error when getting working directory")
		log.Fatal(err)
	}

	watcher := &pkgwatch.Watcher{
		Dir:      dir,
		Debounce: *debounce,
		IsGB:     *c.IsGB,
	}

	worker := &pkgwork.Worker{
		Fn:       execute,
		Cooldown: *cooldown,
	}
	if err := watcher.Run(); err != nil {
		log.Println("error when starting watcher")
		log.Fatal(err)
	}
	defer watcher.Close()

	log.Println("waiting for changes")

	for {
		select {
		case pkg := <-watcher.Changes():
			go func() {
				if err := worker.Run(pkg); err != nil {
					log.Fatal(err)
				}
			}()
		case _ = <-done:
			log.Println("shutting down")
			os.Exit(0)
		}
	}
}
Esempio n. 2
0
func main() {
	var err error

	flag.Parse()
	dotenv.Load()
	signal.Notify(sigs, os.Interrupt, os.Kill)

	cmd, err = cmdtmpl.NewCommand(flag.Args())
	if err != nil {
		log.Fatal(err)
	}

	p, err := cmd.Make(struct{}{})
	if err != nil {
		log.Fatal(err)
	}

	proc = rerun.NewRunner(p, *cooldown)

	dir, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}

	watcher := &pkgwatch.Watcher{
		Dir:      dir,
		Debounce: *debounce,
		IsGB:     *c.IsGB,
	}

	if err := watcher.Run(); err != nil {
		log.Fatal(err)
	}
	defer watcher.Close()

	proc.Start()

	for {
		select {
		case <-watcher.Changes():
			proc.Restart()
		case <-sigs:
			proc.Shutdown()
			os.Exit(0)
		}
	}
}