@@ -15,45 +15,46 @@ To install
1515
1616As an example, create a file ** Gododir/Godofile.go** with this content
1717
18- package main
19-
20- import (
21- . "gopkg.in/godo.v1"
22- )
18+ ``` go
19+ package main
2320
24- func Tasks(p *Project) {
25- Env = "GOPATH=.vendor::$GOPATH PG_PASSWORD=dev"
21+ import (
22+ . " gopkg.in/godo.v1"
23+ )
2624
27- p.Task("default", D{"hello", "build"})
25+ func Tasks (p *Project ) {
26+ Env = " GOPATH=.vendor::$GOPATH PG_PASSWORD=dev"
2827
29- p.Task("hello", func(c *Context) {
30- name := c.Args.ZeroString("name", "n")
28+ p.Task (" default" , D{" hello" , " build" })
3129
32- if name == "" {
33- Bash("echo Hello $USER!")
34- } else {
35- fmt.Println("Hello", name)
36- }
37- })
30+ p.Task (" hello" , func (c *Context) {
31+ name := c.Args .ZeroString (" name" , " n" )
3832
39- p.Task("build", W{"**/*.go"}, func() {
40- Run("GOOS=linux GOARCH=amd64 go build", In{"cmd/server"})
41- })
33+ if name == " " {
34+ Bash (" echo Hello $USER!" )
35+ } else {
36+ fmt.Println (" Hello" , name)
37+ }
38+ })
4239
43- p.Task("views ", W{"templates/ **/*.go.html "}, func() {
44- Run("razor templates" )
45- })
40+ p.Task (" build " , W{" **/*.go" }, func () {
41+ Run ( " GOOS=linux GOARCH=amd64 go build " , In{ " cmd/server " } )
42+ })
4643
47- p.Task("server", D{"views"}, W{"server/**/*.go", "cmd/server/*.{go,json}"}, Debounce(3000), func() {
48- // rebuilds and restarts the process when a watched file changes
49- Start("main.go", In{"cmd/server"})
50- })
51- }
44+ p.Task (" views" , W{" templates/**/*.go.html" }, func () {
45+ Run (" razor templates" )
46+ })
5247
53- func main() {
54- Godo(Tasks)
55- }
48+ p.Task (" server" , D{" views" }, W{" server/**/*.go" , " cmd/server/*.{go,json}" }, Debounce (3000 ), func () {
49+ // rebuilds and restarts the process when a watched file changes
50+ Start (" main.go" , In{" cmd/server" })
51+ })
52+ }
5653
54+ func main () {
55+ Godo (Tasks)
56+ }
57+ ```
5758
5859To run "server" task from parent dir of ` tasks/ `
5960
@@ -69,8 +70,10 @@ To run the "default" task which runs "hello" and "views"
6970
7071Task names may add a "?" suffix to execute only once even when watching
7172
72- // build once regardless of number of dependents
73- p.Task("build?", func() {})
73+ ``` go
74+ // build once regardless of number of dependents
75+ p.Task (" build?" , func () {})
76+ ```
7477
7578Task options
7679
@@ -122,18 +125,24 @@ godo hello -- -n dude
122125Args functions are categorized as
123126
124127* ` Must* ` - Argument must be set by user
125-
126- c.Args.MustInt("number", "n")
128+
129+ ``` go
130+ c.Args .MustInt (" number" , " n" )
131+ ```
127132
128133* ` May* ` - If argument is not set, default to first value in function call
129134
130- // defaults to 100
131- c.Args.MayInt(100, "number", "n")
135+ ``` go
136+ // defaults to 100
137+ c.Args .MayInt (100 , " number" , " n" )
138+ ```
132139
133140* ` Zero* ` - If argument is not set, default to zero value
134141
135- // defaults to 0
136- c.Args.ZeroInt(100, "number", "n")
142+ ``` go
143+ // defaults to 0
144+ c.Args .ZeroInt (100 , " number" , " n" )
145+ ```
137146
138147## Exec functions
139148
@@ -143,32 +152,42 @@ Bash functions uses the bash executable and may not run on all OS.
143152
144153Run a bash script string. The script can be multine line with continutation.
145154
146- Bash(`
147- echo -n $USER
148- echo some really long \
149- command
150- `)
155+ ``` go
156+ Bash (`
157+ echo -n $USER
158+ echo some really long \
159+ command
160+ ` )
161+ ```
151162
152163Run a bash script and capture STDOUT and STDERR.
153164
154- output, err := BashOutput(`echo -n $USER`)
165+ ``` go
166+ output , err := BashOutput (` echo -n $USER` )
167+ ```
155168
156169### Run
157170
158171Run ` go build ` inside of cmd/app and set environment variables.
159172
160- Run(`GOOS=linux GOARCH=amd64 go build`, In{"cmd/app"})
173+ ``` go
174+ Run (` GOOS=linux GOARCH=amd64 go build` , In {" cmd/app" })
175+ ```
161176
162177Run and capture STDOUT and STDERR
163178
164- output, err := RunOutput("whoami")
179+ ``` go
180+ output , err := RunOutput (" whoami" )
181+ ```
165182
166183### Start
167184
168185Start an async command. If the executable has suffix ".go" then it will be "go install"ed then executed.
169186Use this for watching a server task.
170187
171- Start("main.go", In{"cmd/app"})
188+ ``` go
189+ Start (" main.go" , In {" cmd/app" })
190+ ```
172191
173192Godo tracks the process ID of started processes to restart the app gracefully.
174193
@@ -177,39 +196,48 @@ Godo tracks the process ID of started processes to restart the app gracefully.
177196To run many commands inside a directory, use ` Inside ` instead of the ` In ` option.
178197` Inside ` changes the working directory.
179198
180- Inside("somedir", func() {
181- Run("...")
182- Bash("...")
183- })
199+ ``` go
200+ Inside (" somedir" , func () {
201+ Run (" ..." )
202+ Bash (" ..." )
203+ })
204+ ```
184205
185206## Godofile Run-Time Environment
186207
187208To specify whether to inherit from parent's process environment,
188209set ` InheritParentEnv ` . This setting defaults to true
189210
190- InheritParentEnv = false
211+ ``` go
212+ InheritParentEnv = false
213+ ```
191214
192215To specify the base environment for your tasks, set ` Env ` .
193216Separate with whitespace or newlines.
194217
195- Env = `
196- GOPATH=.vendor::$GOPATH
197- PG_USER=mario
198- `
218+ ``` go
219+ Env = `
220+ GOPATH=.vendor::$GOPATH
221+ PG_USER=mario
222+ `
223+ ```
199224
200225TIP: Set the ` Env ` when using a dependency manager like ` godep `
201226
202- wd, _ := os.Getwd()
203- ws := path.Join(wd, "Godeps/_workspace")
204- Env = fmt.Sprintf("GOPATH=%s::$GOPATH", ws)
205-
227+ ``` go
228+ wd , _ := os.Getwd ()
229+ ws := path.Join (wd, " Godeps/_workspace" )
230+ Env = fmt.Sprintf (" GOPATH=%s ::$GOPATH" , ws)
231+ ```
206232Functions can add or override environment variables as part of the command string.
207233Note that environment variables are set before the executable similar to a shell;
208234however, the ` Run ` and ` Start ` functions do not use a shell.
209235
210- p.Task("build", func() {
211- Run("GOOS=linux GOARCH=amd64 go build" )
212- })
236+ ``` go
237+ p.Task (" build" , func () {
238+ Run (" GOOS=linux GOARCH=amd64 go build" )
239+ })
240+ ```
213241
214242The effective environment for exec functions is: ` parent (if inherited) <- Env <- func parsed env `
215243
0 commit comments