watcher

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	// Running must return true when the command is still running.
	Running() bool
	// Exec takes command program with first param, then arguments.
	Exec(params ...string) error
}

Executor provides a minimal workflow to run commands.

func NewPrintExec

func NewPrintExec(output io.Writer) Executor

NewPrintExec only prints to stdout the full file path that triggered an event so you can pipe the output and do whatever you want with it.

func NewRawExec

func NewRawExec(output io.Writer) Executor

NewRawExec will run your command without shell. FIXME: commands with arguments are NOT supported for now.

func NewUnixShellExec

func NewUnixShellExec(output io.Writer) Executor

NewUnixShellExec returns an executor that will run your command through /bin/sh -c "<command>". Your command will be quoted before to avoid any problems.

type Watcher

type Watcher struct {
	Name      string
	Command   string
	Match     string
	Filter    string
	FSWatcher *fsnotify.Watcher
	Shell     string
	Debug     bool
	Logger    *log.Logger
	// contains filtered or unexported fields
}

Watcher ...

func NewWatcher

func NewWatcher(name, match, filter, command string, executor Executor, debug bool, logger *log.Logger) (*Watcher, error)

NewWatcher requires logger and executor to not be nil. param name is purely cosmetic, for logs. param match is a file, directory or "glob" path (shell-like). param command is a single command to run through executor. param executor is an instance of Executor that is not required to honor the given command, like for the Print executor. param debug shows more details when running. param logger must log to stderr when using executor Print.

func (*Watcher) Find

func (w *Watcher) Find() error

Find add files to the watcher. Currently only one file with it's exact path (may be relative) is supported.

func (*Watcher) Work

func (w *Watcher) Work() error

Work fires the watcher and run commands when an event is received.

Jump to

Keyboard shortcuts

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