github.com/markbates/grift@v1.5.0/README.md (about) 1 # Grift 2 3 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). 4 5 ## Why? 6 7 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... 8 9 Grift lets you write these scripts using Go in a really simple and extensible way. 10 11 ## Installation 12 13 Installation is really easy using `go get`. 14 15 ```text 16 $ go get github.com/markbates/grift 17 ``` 18 19 You can confirm the installation by running: 20 21 ```text 22 $ grift jim 23 ``` 24 25 ## Usage/Getting Started 26 27 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. 28 29 By running the following command: 30 31 ```text 32 $ grift init 33 ``` 34 35 When you run the `init` sub-command Grift will generate a new `grifts` package and create a couple of simple grifts for you. 36 37 #### List available grifts 38 39 ```text 40 $ grift list 41 ``` 42 43 #### Say Hello! 44 45 ```text 46 $ grift hello 47 ``` 48 49 ## That's it! 50 51 That's really it! Grift is meant to be simple. Write your grifts, use the full power of Go to do it. 52 53 For more information I would highly recommend checking out the [docs](https://godoc.org/github.com/markbates/grift/grift). 54 55 56 ### Examples: 57 58 ```go 59 package grifts 60 61 import ( 62 "errors" 63 "fmt" 64 "os" 65 "strings" 66 67 . "github.com/markbates/grift/grift" 68 ) 69 70 var _ = Add("boom", func(c *Context) error { 71 return errors.New("boom!!!") 72 }) 73 74 var _ = Add("hello", func(c *Context) error { 75 fmt.Println("Hello World!") 76 return nil 77 }) 78 79 var _ = Add("hello", func(c *Context) error { 80 fmt.Println("Hello World! Again") 81 err := Run("db:migrate", c) 82 if err != nil { 83 return err 84 } 85 dir, err := os.Getwd() 86 if err != nil { 87 return err 88 } 89 fmt.Printf("### dir -> %+v\n", dir) 90 return nil 91 }) 92 93 var _ = Add("env:print", func(c *Context) error { 94 if len(c.Args) >= 1 { 95 for _, e := range c.Args { 96 fmt.Printf("%s=%s\n", e, os.Getenv(e)) 97 } 98 } else { 99 for _, e := range os.Environ() { 100 pair := strings.Split(e, "=") 101 fmt.Printf("%s=%s\n", pair[0], os.Getenv(pair[0])) 102 } 103 } 104 105 return nil 106 }) 107 108 var _ = Namespace("db", func() { 109 Desc("migrate", "Migrates the databases") 110 Set("migrate", func(c *Context) error { 111 fmt.Println("db:migrate") 112 fmt.Printf("### args -> %+v\n", c.Args) 113 return nil 114 }) 115 } 116 ```