All Projects → vrongmeal → Leaf

vrongmeal / Leaf

Licence: mit
General purpose reloader for all projects.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Leaf

Awesome Cli
A curated list of awesome resources for building immersive CLI experiences.
Stars: ✭ 104 (-11.86%)
Mutual labels:  command-line-tool
Nix Deploy
Deploy software or an entire NixOS system configuration to another NixOS system
Stars: ✭ 111 (-5.93%)
Mutual labels:  command-line-tool
Mesabox
A collection of core system utilities written in Rust for Unix-like systems (and now Windows)
Stars: ✭ 116 (-1.69%)
Mutual labels:  command-line-tool
Inferno
🔥 Modern command line tool for malware creation on Windows
Stars: ✭ 105 (-11.02%)
Mutual labels:  command-line-tool
N26
API and CLI to get information of your N26 account
Stars: ✭ 107 (-9.32%)
Mutual labels:  command-line-tool
Jardiff
A tool for comparing JAR files, including Scala pickled signatures and method code
Stars: ✭ 112 (-5.08%)
Mutual labels:  command-line-tool
Simpleaudioindexer
Searching for the occurrence seconds of words/phrases or arbitrary regex patterns within audio files
Stars: ✭ 100 (-15.25%)
Mutual labels:  command-line-tool
Borg
Search and save shell snippets without leaving your terminal
Stars: ✭ 1,528 (+1194.92%)
Mutual labels:  command-line-tool
Splash
A fast, lightweight and flexible Swift syntax highlighter for blogs, tools and fun!
Stars: ✭ 1,529 (+1195.76%)
Mutual labels:  command-line-tool
Droid
A command-line tool for checking Android OS version history written by Rust.
Stars: ✭ 115 (-2.54%)
Mutual labels:  command-line-tool
Iredis
Interactive Redis: A Terminal Client for Redis with AutoCompletion and Syntax Highlighting.
Stars: ✭ 1,661 (+1307.63%)
Mutual labels:  command-line-tool
Giraffez
User-friendly Teradata client for Python
Stars: ✭ 106 (-10.17%)
Mutual labels:  command-line-tool
Endlines
Easy conversion between new-line conventions
Stars: ✭ 112 (-5.08%)
Mutual labels:  command-line-tool
Project Init
Project templates in rust
Stars: ✭ 104 (-11.86%)
Mutual labels:  command-line-tool
Python N26
💵 Unofficial Python client for n26 (Number 26) - https://n26.com/
Stars: ✭ 116 (-1.69%)
Mutual labels:  command-line-tool
Csv2db
The CSV to database command line loader
Stars: ✭ 102 (-13.56%)
Mutual labels:  command-line-tool
Hmap
hmap is a command line tool written in Swift to work with Clang header maps produced by Xcode.
Stars: ✭ 110 (-6.78%)
Mutual labels:  command-line-tool
Freenom Dns Updater
A tool to update freenom's dns records
Stars: ✭ 117 (-0.85%)
Mutual labels:  command-line-tool
Elixir cli spinners
Spinnig Animations for Command Line Applications
Stars: ✭ 117 (-0.85%)
Mutual labels:  command-line-tool
Git Chglog
CHANGELOG generator implemented in Go (Golang).
Stars: ✭ 1,895 (+1505.93%)
Mutual labels:  command-line-tool

leaf

General purpose reloader for all projects.

Continuous Integration

Command leaf watches for changes in the working directory and runs the specified set of commands whenever a file updates. A set of filters can be applied to the watch and directories can be excluded.

Contents

  1. Installation
    1. Using go get
    2. Manual
  2. Usage
    1. Command line help
    2. Configuration file
  3. Custom reloader

Installation

Using go get

The following command will download and build Leaf in your $GOPATH/bin.

❯ go get -u github.com/vrongmeal/leaf/cmd/leaf

Manual

  1. Clone the repository and cd into it.
  2. Run make build to build the leaf as build/leaf.
  3. Move the binary somewhere in your $PATH.

Usage

❯ leaf -x 'make build' -x 'make run'

The above command runs make build and make run commands (in order).

Command line help

The CLI can be used as described by the help message:

❯ leaf help

Command leaf watches for changes in the working directory and
runs the specified set of commands whenever a file updates.
A set of filters can be applied to the watch and directories
can be excluded.

Usage:
  leaf [flags]
  leaf [command]

Available Commands:
  help        Help about any command
  version     prints leaf version

Flags:
  -c, --config string     config path for the configuration file (default "<CWD>/.leaf.yml")
      --debug             run in development (debug) environment
  -d, --delay duration    delay after which commands are run on file change (default 500ms)
  -e, --exclude strings   paths to exclude from watching (default [.git/,node_modules/,vendor/,venv/])
  -x, --exec strings      exec commands on file change
  -z, --exit-on-err       exit chain of commands on error
  -f, --filters strings   filters to apply to watch
  -h, --help              help for leaf
  -o, --once              run once and exit (no reload)
  -r, --root string       root directory to watch (default "<CWD>")

Use "leaf [command] --help" for more information about a command.

Configuration file

In order to configure using a configuration file, create a YAML or TOML or even a JSON file with the following structure and pass it using the -c or --config flag. By default a file named .leaf.yml in your working directory is taken if no configuration file is found.

# Leaf configuration file.

# Root directory to watch.
# Defaults to current working directory.
root: .

# Exclude directories while watching.
# If certain directories are not excluded, it might reach a
# limitation where watcher doesn't start.
exclude:
  - DEFAULTS # This includes the default ignored directories
  - build/
  - scripts/

# Filters to apply on the watch.
# Filters starting with '+' are includent and then with '-'
# are excluded. This is not like exclude, these are still
# being watched yet can be excluded from the execution.
# These can include any regex supported by filepath.Match
# method or even a directory.
filters:
  - '+ go.mod'
  - '+ go.sum'
  - '+ *.go'
  - '+ cmd/'

# Commands to be executed. These are run in the provided order.
exec:
  - make format
  - make build

# Stop the command chain when an error occurs
exit_on_err: true

# Delay after which commands are executed.
delay: 1s

The above config file is suitable to use with the current project itself. It can also be translated into a command as such:

❯ leaf -z -x 'make format' -x 'make build' -d '1s' \
  -e 'DEFAULTS' -e 'build' -e 'scripts' \
  -f '+ go.*' -f '+ *.go' -f '+ cmd/'

Custom reloader

The package github.com/vrongmeal/leaf comes with utilities that can aid in creating a reloader with a simple go program.

Let's look at an example where the watcher watches the src/ directory for changes and for any changes builds the project.

package main

import (
	"fmt"
	"log"
	"os"
	"path/filepath"

	"github.com/vrongmeal/leaf"
)

func main() {
	// Use a context that cancels when program is interrupted.
	ctx := leaf.NewCmdContext(func(os.Signal) {
		log.Println("Shutting down.")
	})

	cwd, err := os.Getwd()
	if err != nil {
		log.Fatalln(err)
	}

	// Root is <cwd>/src
	root := filepath.Join(cwd, "src")

	// Exclude "src/index.html" from results.
	filters := []leaf.Filter{
		{Include: false, Pattern: "src/index.html"},
	}

	filterCollection := leaf.NewFilterCollection(
		filters,
		// Matches directory or filepath.Match expressions
		leaf.StandardFilterMatcher,
		// Definitely excludes and shows only includes (if any)
		leaf.StandardFilterHandler)

	watcher, err := leaf.NewWatcher(
		root,
		// Standard paths to exclude, like vendor, .git,
		// node_modules, venv etc.
		leaf.DefaultExcludePaths,
		filterCollection)
	if err != nil {
		log.Fatalln(err)
	}

	cmd, err := leaf.NewCommand("npm run build")
	if err != nil {
		log.Fatalln(err)
	}

	log.Printf("Watching: %s\n", root)

	for change := range watcher.Watch(ctx) {
		if change.Err != nil {
			log.Printf("ERROR: %v", change.Err)
			continue
		}
		// If no error run the command
		fmt.Printf("Running: %s\n", cmd.String())
		cmd.Execute(ctx)
	}
}

Made with khoon, paseena and love :-) by

Vaibhav (vrongmeal)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].