grift
所属分类:hotest
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2020-05-05 22:30:34
上 传 者:
sh-1993
说明: 基于Go的任务运行器
(Go based task runner)
文件列表:
.goreleaser.yml (459, 2019-11-16)
.goreleaser.yml.plush (383, 2019-11-16)
.travis.yml (157, 2019-11-16)
LICENSE (1077, 2019-11-16)
Makefile (1007, 2019-11-16)
azure-pipelines.yml (1545, 2019-11-16)
azure-tests.yml (459, 2019-11-16)
cli/ (0, 2019-11-16)
cli/help.go (194, 2019-11-16)
cli/help_test.go (318, 2019-11-16)
cli/init.go (1184, 2019-11-16)
cli/io.go (835, 2019-11-16)
cli/jim.go (4580, 2019-11-16)
cli/main.go (720, 2019-11-16)
cli/main_test.go (1080, 2019-11-16)
cli/run.go (1183, 2019-11-16)
cli/run_test.go (516, 2019-11-16)
cli/tmpl.go (248, 2019-11-16)
cli/version.go (38, 2019-11-16)
cmd/ (0, 2019-11-16)
cmd/run.go (221, 2019-11-16)
go.mod (126, 2019-11-16)
go.sum (1807, 2019-11-16)
grift/ (0, 2019-11-16)
grift/context.go (1095, 2019-11-16)
grift/context_test.go (556, 2019-11-16)
grift/grift.go (4239, 2019-11-16)
grift/grift_test.go (3621, 2019-11-16)
grifts/ (0, 2019-11-16)
grifts/example.go (336, 2019-11-16)
main.go (781, 2019-11-16)
shoulders.md (1127, 2019-11-16)
# Grift
Grift is a very simple library that allows you to write simple "task" scripts in Go and run them by name without having to write big `main` type of wrappers. Grift is similar to, and inspired by, [Rake](http://rake.rubyforge.org).
## Why?
Excellent question! When building applications there comes a point where you need different scripts to do different things. For example, you might want a script to seed your database, or perhaps a script to parse some logs, etc...
Grift lets you write these scripts using Go in a really simple and extensible way.
## Installation
Installation is really easy using `go get`.
```text
$ go get github.com/markbates/grift
```
You can confirm the installation by running:
```text
$ grift jim
```
## Usage/Getting Started
Apart from having the binary installed, the only other requirement is that the package you place your grifts in is called `grifts`. That's it.
By running the following command:
```text
$ grift init
```
When you run the `init` sub-command Grift will generate a new `grifts` package and create a couple of simple grifts for you.
#### List available grifts
```text
$ grift list
```
#### Say Hello!
```text
$ grift hello
```
## That's it!
That's really it! Grift is meant to be simple. Write your grifts, use the full power of Go to do it.
For more information I would highly recommend checking out the [docs](https://godoc.org/github.com/markbates/grift/grift).
### Examples:
```go
package grifts
import (
"errors"
"fmt"
"os"
"strings"
. "github.com/markbates/grift/grift"
)
var _ = Add("boom", func(c *Context) error {
return errors.New("boom!!!")
})
var _ = Add("hello", func(c *Context) error {
fmt.Println("Hello World!")
return nil
})
var _ = Add("hello", func(c *Context) error {
fmt.Println("Hello World! Again")
err := Run("db:migrate", c)
if err != nil {
return err
}
dir, err := os.Getwd()
if err != nil {
return err
}
fmt.Printf("### dir -> %+v\n", dir)
return nil
})
var _ = Add("env:print", func(c *Context) error {
if len(c.Args) >= 1 {
for _, e := range c.Args {
fmt.Printf("%s=%s\n", e, os.Getenv(e))
}
} else {
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
fmt.Printf("%s=%s\n", pair[0], os.Getenv(pair[0]))
}
}
return nil
})
var _ = Namespace("db", func() {
Desc("migrate", "Migrates the databases")
Set("migrate", func(c *Context) error {
fmt.Println("db:migrate")
fmt.Printf("### args -> %+v\n", c.Args)
return nil
})
}
```
近期下载者:
相关文件:
收藏者: