Debian Codegraph @

book/getting_started/README.md

raw symbols SCIP
1 # Getting Started
2
3 Create a file `Gododir/main.go` with this content
4
5 ```go
6 import (
7 "fmt"
8 do "gopkg.in/godo.v2"
9 )
10
11 func tasks(p *do.Project) {
12 p.Task("hello", nil, func(c *do.Context) {
13 name := c.Args.AsString("world", "name", "n")
14 fmt.Println("Hello", name, "!")
15 }
16 }
17
18 func main() {
19 do.Godo(tasks)
20 }
21 ```
22
23 From your terminal run
24
25 ```
26 # prints "Hello world!"
27 godo hello
28
29 # prints "Hello gopher!"
30 godo hello -- n="gopher"
31
32 # prints "Hello gopher!"
33 godo hello -- name="gopher"
34 ```
35
36 Let's create a non-trivial example to run tests whenever any go file changes
37
38 ```go
39 import . "gopkg.in/godo.v2"
40
41 func tasks(p *do.Project) {
42 p.Task("clean", nil, func(c *do.Context) {
43 c.Run("rm -rf tmp")
44 }
45
46 p.Task("assets", nil, func(c *do.Context) {
47 // Version is from external version.go
48 versionDir := "dist/public/v" + Version
49 c.Bash(`
50 set -e
51 mkdir -p {{.versionDir}}
52 browserify . -o {{.versionDir}}
53 `, M{"versionDir": versionDir})
54 }
55
56 p.Task("build", nil, func(c *do.Context) {
57 c.Run("go build", M{"$in", "cmd/app"})
58 }.Src("cmd/app/**/*.go")
59
60 p.Task("test", nil, func(c *do.Context) {
61 c.Run("go test")
62 }.Src("**/*.go")
63
64 // S or Series, P or Parallel
65 p.Task("default", S{"clean", P{"build", "assets"}, "test"}, nil)
66 }
67 ```
68
69 From your terminal run
70
71 ```sh
72 godo -w
73 ```
74
75 That simple statement does the following
76
77 * **godo** runs "default" task. **godo** runs the "default" task in the absence of a task name.
78 * The "default" task declares a set of dependencies qualified by the order in which they should be executed. The dependency
79
80 ```go
81 S{P{"clean", "build"}, "test"}
82 ```
83
84 means. Run the following in a series.
85
86 1. Run "clean" and "build" in parallel
87 2. Then, run "test"
88