Example #1
0
func main() {
	paths := kingpin.Arg(
		"path",
		"Paths to monitor for changes.",
	).Required().Strings()
	kingpin.Parse()

	modchan := make(chan modd.Mod)
	for _, path := range *paths {
		err := modd.Watch(path, batchTime, modchan)
		if err != nil {
			kingpin.Fatalf("Fatal error: %s", err)
		}
	}
	for mod := range modchan {
		if len(mod.Added) > 0 {
			fmt.Printf("Added: %v\n", mod.Added)
		}
		if len(mod.Changed) > 0 {
			fmt.Printf("Changed: %v\n", mod.Changed)
		}
		if len(mod.Deleted) > 0 {
			fmt.Printf("Removed: %v\n", mod.Deleted)
		}
	}
}
Example #2
0
// Watch watches an endpoint for changes, if it supports them.
func (r Route) Watch(ch chan []string, excludePatterns []string, log termlog.Logger) error {
	switch r.Endpoint.(type) {
	case *filesystemEndpoint:
		ep := *r.Endpoint.(*filesystemEndpoint)
		modchan := make(chan modd.Mod, 1)
		err := modd.Watch(string(ep), batchTime, modchan)
		if err != nil {
			return err
		}
		go func() {
			for mod := range modchan {
				files := filterFiles(mod.All(), excludePatterns, log)
				ch <- files
			}
		}()
	}
	return nil
}
Example #3
0
File: main.go Project: rawbite/devd
func main() {
	paths := kingpin.Arg(
		"path",
		"Paths to monitor for changes.",
	).Required().Strings()
	kingpin.Parse()

	pathchan := make(chan []string)
	for _, path := range *paths {
		err := modd.Watch(path, batchTime, pathchan)
		if err != nil {
			kingpin.Fatalf("Fatal error: %s", err)
		}
	}
	for paths := range pathchan {
		fmt.Println(paths)
	}
}
Example #4
0
// WatchPaths watches a set of paths, and broadcasts changes through reloader.
func WatchPaths(paths, excludePatterns []string, reloader livereload.Reloader, log termlog.Logger) error {
	ch := make(chan []string, 1)
	for _, path := range paths {
		modchan := make(chan modd.Mod, 1)
		err := modd.Watch(path, batchTime, modchan)
		if err != nil {
			return err
		}
		go func() {
			for mod := range modchan {
				files := filterFiles(mod.All(), excludePatterns, log)
				if len(files) > 0 {
					ch <- files
				}
			}
		}()
	}
	go reloader.Watch(ch)
	return nil
}