watcher

package module
v0.0.0-...-4ffc86c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2016 License: MIT Imports: 10 Imported by: 2

README

Orivil File Watcher

Introduction

A tool for automatically running a custom command or running a custom method when detected file's changing.

Install

go get -v gopkg.in/orivil/watcher.v0

GO Auto Builder Example:

autobuild.go:

package main

import (
	"gopkg.in/orivil/watcher.v0"
	"log"
	"os"
	"strings"
	"path/filepath"
)

func main() {
	// watch ".go" file
	extensions := []string{".go"}

	// handle incoming errors
	var errHandler = func(e error) {

		log.Println(e)
	}

	runner := watcher.NewAutoCommand(extensions, errHandler)

	// watch library directories
	goPath, _ := os.LookupEnv("GOPATH")
	goPaths := strings.Split(goPath, ";")
	for _, path := range goPaths {
		if path != "" {
			runner.Watch(filepath.Join(path, "src"))
		}
	}

	// build current directory
	buildFile := "."

	// run the watcher and wait for event.
	runner.RunCommand("go", "build", buildFile)
}

Open terminal: go install autobuild.go.

Then you can use command "autobuild" under your project directory to build your project automatically.

Note: If command "autobuild" does not exist, add the path "$GOPATH/bin" to your PATH environment variable.

Contributors

https://github.com/orivil/watcher/graphs/contributors

License

Released under the MIT License.

Documentation

Overview

Package watcher provides a tool for automatically running a custom command or running a custom method when detected file's changing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoCommand

type AutoCommand struct {
	// contains filtered or unexported fields
}

func NewAutoCommand

func NewAutoCommand(exts []string, errHandle func(e error)) *AutoCommand

Param exts provides the file name extensions for file watcher. Param errHandle is used to handle incoming errors.

func (*AutoCommand) RunCommand

func (b *AutoCommand) RunCommand(command string, args ...string)

RunCommand depends on RunFunc, the given command will be run when file watcher detected file changing.

func (*AutoCommand) RunFunc

func (b *AutoCommand) RunFunc(h func())

RunFunc runs the h when detected file changing. This function will wait for interrupt or terminate signal.

func (*AutoCommand) Watch

func (b *AutoCommand) Watch(dir ...string)

Watch provides the directories which need to listen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL