rizla

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package rizla contains the source code of the rizla project

Index

Constants

This section is empty.

Variables

View Source
var DefaultDisableProgramRerunOutput = false

DefaultDisableProgramRerunOutput a long name but, it disables the output of the program's 'messages' after the first successfully run for each of the projects the project iteral can be override this value. set to true to disable the program's output when reloads

View Source
var DefaultWalkLoopSleep = 1350 * time.Second

DefaultWalkLoopSleep it's the sleep time of the loop when --walk flag is used(`filepath#Walk`). Defaults to 1.3 second.

View Source
var OnReloadScripts []string

OnReloadScripts simple file names which will execute a script, i.e `./on_reload.sh` or `./on_reload.bat` or even `service supervisor restart` on windows, it will just execute that based on the operating system, nothing crazy here, they are filled by the cli but they can be customized by the source as well.

If contains whitespaces, after the first whitespace they are the command's flags (if not a script file).

View Source
var (
	// Out is the logger which prints watcher errors and information.
	//
	// Change its printer's Output (io.Writer) by `Out.SetOutput(io.Writer)`.
	Out = golog.New().SetOutput(os.Stdout)
)

Functions

func Add

func Add(proj ...*Project)

Add project(s) to the container

func DefaultGoMatcher

func DefaultGoMatcher(fullname string) bool

DefaultGoMatcher is the default Matcher for the Project iteral

func DefaultOnReload

func DefaultOnReload(p *Project) func(string)

DefaultOnReload fired when file has changed and reload going to happens

func DefaultOnReloaded

func DefaultOnReloaded(p *Project) func(string)

DefaultOnReloaded fired when reload has been finished. Defaults to noOp.

func DefaultWatcher

func DefaultWatcher(abs string) bool

DefaultWatcher is the default Watcher for the Project iteral allows all subdirs except .git, node_modules and vendor

func Len

func Len() int

Len how much projects have been added so far

func RemoveAll

func RemoveAll()

RemoveAll clears the current projects, doesn't stop them if running

func Run

func Run(sources map[string][]string)

Run same as RunWith but runs with the default file system watcher which is the fsnotify (watch over file system's signals) or the last used with RunWith.

It's a map of main files and their arguments, if any.

func RunWith added in v1.0.0

func RunWith(watcher Watcher, sources map[string][]string, delayOnDetect time.Duration)

RunWith starts the repeat of the build-run-watch-reload task of all projects receives optional parameters which can be the main source file of the project(s) you want to add, they can work nice with .Add(project) also, so dont worry use it.

First receiver is the type of watcher second (optional) parameter(s) are the directories of the projects.

it's optional because they can be added with the .Add(NewProject) before the RunWith.

func Stop

func Stop()

Stop any projects are watched by the RunWith/Run method, this function should be call when you call the Run inside a goroutine.

Types

type MatcherFunc

type MatcherFunc func(string) bool

MatcherFunc returns whether the file should be watched for the reload

type Project

type Project struct {
	// optional Name for the project
	Name string
	// MainFile is the absolute path of the go project's main file source.
	MainFile string
	// The application's name, usually is the MainFile withotu the extension.
	// At the future we may provide a way for custom naming which will be used on the "go build -o" flag.
	AppName string
	Args    []string
	// The Output destination (sent by rizla and your program)
	Out *golog.Logger
	// The Err Output destination (sent on rizla errors and your program's errors)
	Err *golog.Logger
	// Watcher accepts subdirectories by the watcher
	// executes before the watcher starts,
	// if return true, then this (absolute) subdirectory is watched by watcher
	// the default accepts all subdirectories but ignores the ".git", "node_modules" and "vendor"
	Watcher MatcherFunc
	Matcher MatcherFunc
	// AllowReloadAfter skip reload on file changes that made too fast from the last reload
	// minimum allowed duration is 3 seconds.
	AllowReloadAfter time.Duration
	// AllowRunAfter it accepts the file changes
	// but it waits "x" duration for the reload to happen.
	AllowRunAfter time.Duration
	// OnReload fires when when file has been changed and rizla is going to reload the project
	// the parameter is the changed file name
	OnReload func(string)
	// OnReloaded fires when rizla finish with the reload
	// the parameter is the changed file name
	OnReloaded func(string)
	// DisableRuntimeDir set to true to disable adding subdirectories into the watcher, when a folder created at runtime
	// set to true to disable the program's output when reloads
	// defaults to false
	DisableRuntimeDir bool
	// DisableProgramRerunOutput a long name but, it disables the output of the program's 'messages' after the first successfully run
	// defaults to false
	DisableProgramRerunOutput bool
	// contains filtered or unexported fields
}

Project the struct which contains the necessary fields to watch and reload(rerun) a go project

func NewProject

func NewProject(mainfile string, args ...string) *Project

NewProject returns a simple project iteral which doesn't needs argument parameters and has the default file matcher ( which is valid if you want to reload only on .Go files).

You can change all of its fields before the .Run function.

type Watcher added in v1.0.0

type Watcher interface {
	// OnChange registers an event listener which fires when a file change occurs.
	OnChange(WatcherChangeListener)
	// OnError registers an event listener which fires when a watcher error occurs.
	OnError(WatcherErrorListener)

	// Loop starts the watching and the loop.
	Loop()
	// Stop terminates the watcher.
	Stop()
}

Watcher a common interface which file system watchers should implement.

func WatcherFromFlag added in v1.0.0

func WatcherFromFlag(flag string) (Watcher, bool)

WatcherFromFlag returns a new Watcher based on a string flah. This method keeps the watchers in the same spot.

Note: this is why the internal watchers are not exported.

type WatcherChangeListener added in v1.0.0

type WatcherChangeListener func(p *Project, filename string)

WatcherChangeListener the form the OnChage event listener. Receives the project which the change is valid (see Project.AllowReloadAfter) and a second parameter which is the relative path to the changed file or directory.

type WatcherErrorListener added in v1.0.0

type WatcherErrorListener func(error)

WatcherErrorListener the form the OnError event listener.

Jump to

Keyboard shortcuts

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