As of December 1st, 2019 Buffalo, and all related packages, require Go Modules and the use of the
GOPATH
is no longer supported.
Please see this blog post for more information https://blog.gobuffalo.io/the-road-to-1-0-requiring-modules-5672c6b015e5.
Tasks
Tasks are small scripts that are often needed when writing an application. These tasks might be along the lines of seeding a database, parsing a log file, or even a release script. Buffalo uses the grift package to make writing these tasks simple.
Writing Tasks
Tasks must all be in the grifts
package. A simple task would look like following:
var _ = grift.Add("hello", func(c *grift.Context) error {
fmt.Println("Hello!")
return nil
})
Tasks Generator
$ buffalo g task foo:bar
--> grifts/bar.go
// grifts/bar.go
package grifts
import (
. "github.com/markbates/grift/grift"
)
var _ = Namespace("foo", func() {
Desc("bar", "TODO")
Add("bar", func(c *Context) error {
return nil
})
})
Listing Available Tasks
$ buffalo task list
Available grifts
================
buffalo task middleware # Prints out your middleware stack
buffalo task routes # Print out all defined routes
buffalo task secret # Generate a cryptographically secure secret key
Running Tasks
Development
Tasks can be run in development using the buffalo task
command.
$ buffalo task hello
From a Built Binary
After a binary has been built, the tasks can be run with the task
subcommand:
$ myapp task hello
Feedback
If you found an error or something which needs to be improved, and you want to contribute to fix it:
If you'd like to suggest something to improve this page: