dux

package module
v0.0.0-...-68a54b6 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 8 Imported by: 0

README

dux

Go Reference Go Report Card

The tiny live reload tool

Dux monitors all files in a directory and reloads a given program if any of those files change.

Installation and Usage

$ go install github.com/mleone10/dux/cmd/dux
$ dux -h
Usage of dux:
  -c string
    	linux shell command to execute
  -d string
    	directory to monitor for changes (default ".")
  -freq int
    	frequency at which the directory will be scanned, in seconds (default 1)

Documentation

Overview

Package dux contains types which enable active monitoring and reloading of a program.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Closer

type Closer interface {
	Close()
}

A Closer is any type with a Close() method.

type ExecEngine

type ExecEngine struct {
	Cmd     string
	Args    []string
	Watcher Watcher
}

ExecEngine combines a command, arguments, and a watcher which triggers a reload of the command.

func (ExecEngine) Run

func (e ExecEngine) Run(ctx context.Context)

Run executes ExecEngine.Cmd with ExecEngine.Args, then waits for ExecEngine.Watcher to unblock. When it does, Run kills the command and reruns it. This continues until the context is canceled. TODO: Stop Run when context is canceled

type FileWatcher

type FileWatcher struct {
	FileSystem fs.FS
	PollFreq   time.Duration
}

FileWatcher monitors a given file system, checking all files within at the given polling frequency.

func (FileWatcher) Watch

func (fw FileWatcher) Watch(ctx context.Context)

Watch monitors the FileWatcher file system for changes, blocking until either the context is canceled or a change is detected.

type FuncEngine

type FuncEngine struct {
	Func    func() Closer
	Watcher Watcher
}

A FuncEngine combines a function (which returns a Closer) with a Watcher which triggers that function's reload.

func (FuncEngine) Run

func (e FuncEngine) Run(ctx context.Context)

Run executes FuncEngine.Func, then waits for FuncEngine.Watcher to unblock. When it does, Func's Close method is called and Func is rerun.

type TimeWatcher

type TimeWatcher struct {
	Delay time.Duration
}

TimeWatcher is a Watcher that triggers at a set interval.

func (TimeWatcher) Watch

func (t TimeWatcher) Watch(ctx context.Context)

Watch blocks until TimeWatcher.Delay duration passes or the context is canceled.

type Watcher

type Watcher interface {
	Watch(context.Context)
}

A Watcher blocks until a trigger occurs or the context is canceled.

Directories

Path Synopsis
cmd
dux

Jump to

Keyboard shortcuts

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