runcommand

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBufSize = 10000

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config func(*RunCommand)

func BufSize

func BufSize(bfsize int) Config

func Ignore

func Ignore(i *regexp.Regexp) Config

func KillOnChange

func KillOnChange() Config

if killOnChange is true the running process will be killed, if there is a change

func MatchFiles

func MatchFiles(m *regexp.Regexp) Config

func Sleep

func Sleep(s time.Duration) Config

func Stderr

func Stderr(stderr io.Writer) Config

func Stdout

func Stdout(stdout io.Writer) Config

func Verbose added in v0.0.4

func Verbose() Config

type RunCommand

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

func New

func New(watchDir, runCmd string, configs ...Config) *RunCommand

New creates a new RunCommand that runs runCmd on changes within watchDir or any of its subdirectories. No two instances of runCmd will be running at the same time. Before calling runCmd, the substring $_file will be replaced by the file path of the file that was created/modified and $_wd will be replaced by the path of watchDir. If runCmd does not contain the placeholder $_file, it will not just be called on file creation and file changes, but also when files are renamed of removed. Optional Configs are Stdout(): setting the stdout of the running process (default: os.Stdout) Stderr(): setting the stderr of the running process (default: os.Stderr) BufSize(): setting the buffer size of the reporting channels (default: DefaultBufSize) Ignore(): setting the regular expression to which matching files and directories are ignored (default: nil; ignore nothing) MatchFiles(): setting the regular expression to which file must match in order to be tracked (default: nil; all files match) Sleep(): setting the duration of sleeping time of two invocations of the running command (default: 0; no sleeping time)

func (*RunCommand) Run

func (rc *RunCommand) Run(errors chan error) (Stoppable, error)

Run initiates the watching and running goroutines. Errors while watching are reported to the error channel. If the watcher or the observer could not be initialized properly, an error is returned. Otherwise the returned Stoppable can be used to terminate and kill the running process and end the observation

type Stoppable

type Stoppable interface {
	Kill() error
	Terminate(time.Duration) error
}

Jump to

Keyboard shortcuts

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