Documentation ¶
Overview ¶
Package godo is a task runner, file watcher in the spirit of Rake, Gulp ...
To install
go get -u gopkg.in/godo.v1/cmd/godo
As an example, create a file 'tasks/Godofile.go' with this content
package main import ( . "gokpkg.in/godo.v1" ) func Tasks(p *Project) { Env = "GOPATH=.vendor:$GOPATH OTHER_VAR=val" p.Task("default", D{"hello", "build"}) p.Task("hello", func() { Bash("echo Hello $USER!") }) p.Task("build", W{"**/*.go"}, func() { Run("GOOS=linux GOARCH=amd64 go build", In{"cmd/godo"}) }) p.Task("server", D{"views"}, W{"**/*.go"}, Debounce(3000), func() { // Start recompiles and restarts on changes when watching Start("main.go", In{"cmd/server"}) }) } func main() { Godo(Tasks) }
To run "views" task from terminal
godo views
To rerun "views" whenever any `*.go.html` file changes
godo views --watch
To run the "default" task which runs "hello" and "views"
godo
Task names may add a "?" suffix to indicate run only once
// run once regardless of number of dependees p.Task("build?", func() {})
Task options
D{} or Dependencies{} - dependent tasks which run before task Debounce - minimum milliseconds before task can run again W{} or Watches{} - array of glob file patterns to watch /**/ - match zero or more directories {a,b} - match a or b, no spaces * - match any non-separator char ? - match a single non-separator char **/ - match any directory, start of pattern only /** - match any this directory, end of pattern only ! - removes files from resultset, start of pattern only
Task handlers
func() {} - Simple function handler func(c *Context) {} - Handler which accepts the current context
Index ¶
- Variables
- func Bash(script string, wd ...In) error
- func BashOutput(script string, wd ...In) (string, error)
- func Glob(patterns []string) ([]*FileAsset, []*RegexpInfo, error)
- func Globexp(glob string) *regexp.Regexp
- func Godo(tasksFunc func(*Project))
- func Inside(dir string, lambda func()) error
- func Run(commandstr string, wd ...In) error
- func RunOutput(commandstr string, wd ...In) (string, error)
- func SetEnviron(envstr string, inheritParent bool)
- func Start(commandstr string, wd ...In) error
- func Usage(tasks string)
- type Context
- type ContextHandlerFunc
- type D
- type Debounce
- type Dependencies
- type FileAsset
- type Handler
- type HandlerFunc
- type In
- type M
- type Project
- func (project *Project) Define(fn func(*Project))
- func (project *Project) Run(name string) error
- func (project *Project) Task(name string, args ...interface{}) *Task
- func (project *Project) Use(namespace string, tasksFunc func(*Project))
- func (project *Project) Watch(names []string, isParent bool) bool
- type RegexpInfo
- type Task
- type VoidContextHandlerFunc
- type VoidHandlerFunc
- type W
- type Watch
Constants ¶
This section is empty.
Variables ¶
var DebounceMs int64
DebounceMs is the default time (1500 ms) to debounce task events in watch mode.
var Env string
Env is the default environment to use for all commands. That is, the effective environment for all commands is the merged set of (parent environment, Env, func specified environment). Whitespace or newline separate key value pairs. $VAR interpolation is allowed.
Env = "GOOS=linux GOARCH=amd64" Env = `
GOOS=linux GOPATH=./vendor:$GOPATH
`
var InheritParentEnv bool
InheritParentEnv whether to inherit parent's environment
var PathListSeparator = "::"
PathListSeparator is a cross-platform path list separator. On Windows, PathListSeparator is replacd by ";". On others, PathListSeparator is replaced by ":"
var Version = "1.4.0"
Version is the current version
Functions ¶
func Bash ¶ added in v1.1.0
Bash executes a bash script (string) with an option to set the working directory.
func BashOutput ¶ added in v1.1.0
BashOutput is the same as Bash and it captures stdout and stderr.
func Glob ¶
func Glob(patterns []string) ([]*FileAsset, []*RegexpInfo, error)
Glob returns files and dirctories that match patterns. Patterns must use slashes, even Windows.
Special chars.
/**/ - match zero or more directories {a,b} - match a or b, no spaces * - match any non-separator char ? - match a single non-separator char **/ - match any directory, start of pattern only /** - match any this directory, end of pattern only ! - removes files from resultset, start of pattern only
func Globexp ¶
Globexp builds a regular express from from extended glob pattern and then returns a Regexp object from the pattern.
func Inside ¶ added in v1.1.0
Inside temporarily changes the working directory and restores it when lambda finishes.
func SetEnviron ¶ added in v1.3.0
SetEnviron sets the environment for child processes. Note that SetEnviron(Env, InheritParentEnv) is called once automatically.
Types ¶
type Context ¶
type Context struct { // Task is the currently running task. Task *Task // FileEvent is an event from the watcher with change details. FileEvent *watcher.FileEvent // Task command line arguments Args minimist.ArgMap }
Context is the data passed to a task.
type ContextHandlerFunc ¶ added in v1.3.2
ContextHandlerFunc is a Handler adapter.
func (ContextHandlerFunc) Handle ¶ added in v1.3.2
func (c ContextHandlerFunc) Handle(ctx *Context) error
Handle implements Handler.
type Debounce ¶
type Debounce int64
Debounce is the number of milliseconds before a task can run again.
type Handler ¶ added in v1.3.2
Handler is the interface which all task handlers eventually implement.
type HandlerFunc ¶ added in v1.3.2
type HandlerFunc func() error
HandlerFunc is Handler adapter.
func (HandlerFunc) Handle ¶ added in v1.3.2
func (f HandlerFunc) Handle(*Context) error
Handle implements Handler.
type In ¶ added in v1.1.0
type In []string
In is used by Bash, Run and Start to set the working directory
type Project ¶
type Project struct { sync.Mutex Tasks map[string]*Task Namespace map[string]*Project // contains filtered or unexported fields }
Project is a container for tasks.
func NewProject ¶
NewProject creates am empty project ready for tasks.
type RegexpInfo ¶
RegexpInfo contains additional info about the Regexp created by a glob pattern.
type Task ¶
type Task struct { Name string Dependencies []string Handler Handler // Watches are the files are watched. On change the task is rerun. For example `**/*.less` // Usually Watches and Sources are the same. WatchFiles []*FileAsset WatchGlobs []string WatchRegexps []*RegexpInfo // computed based on dependencies EffectiveWatchRegexps []*RegexpInfo EffectiveWatchGlobs []string // Complete indicates whether this task has already ran. This flag is // ignored in watch mode. Complete bool RunOnce bool // contains filtered or unexported fields }
A Task is an operation performed on a user's project directory.
func (*Task) Description ¶
Description sets the description for the task.
func (*Task) Run ¶
func (task *Task) Run()
Run runs all the dependencies of this task and when they have completed, runs this task.
func (*Task) RunWithEvent ¶
RunWithEvent runs this task when triggered from a watch. *e* FileEvent contains information about the file/directory which changed in watch mode.
type VoidContextHandlerFunc ¶ added in v1.3.2
type VoidContextHandlerFunc func(*Context)
VoidContextHandlerFunc is a Handler adapter.
func (VoidContextHandlerFunc) Handle ¶ added in v1.3.2
func (f VoidContextHandlerFunc) Handle(ctx *Context) error
Handle implements Handler.
type VoidHandlerFunc ¶ added in v1.3.2
type VoidHandlerFunc func()
VoidHandlerFunc is a Handler adapter.
func (VoidHandlerFunc) Handle ¶ added in v1.3.2
func (v VoidHandlerFunc) Handle(*Context) error
Handle implements Handler.