Пример #1
0
func tasks(p *do.Project) {
	p.Task("test", nil, func(c *do.Context) {
		c.Run("go test")
	})

	p.Task("test", do.S{"build"}, func(c *do.Context) {
		c.Run("go test")
	})

	p.Task("dist", do.S{"test", "lint"}, nil)

	p.Task("install", nil, func(c *do.Context) {
		c.Run("go get github.com/golang/lint/golint")
		// Run("go get github.com/mgutz/goa")
		c.Run("go get github.com/robertkrimen/godocdown/godocdown")
	})

	p.Task("lint", nil, func(c *do.Context) {
		c.Run("golint .")
		c.Run("gofmt -w -s .")
		c.Run("go vet .")
	})

	// p.Task("readme", func() {
	// 	Run("godocdown -o README.md")
	// 	// add godoc
	// 	goa.Pipe(
	// 		f.Load("./README.md"),
	// 		f.Str(str.ReplaceF("--", "\n[godoc](https://godoc.org/gopkg.in/godo.v2)\n", 1)),
	// 		f.Write(),
	// 	)
	// })

	p.Task("build", nil, func(c *do.Context) {
		c.Run("go install", do.M{"$in": "cmd/godo"})
	})

	p.Task("interactive", nil, func(c *do.Context) {
		c.Bash(`
			echo name?
			read name
			echo hello $name
		`)
	})

	p.Task("whoami", nil, func(c *do.Context) {
		c.Run("whoami")
	})

	pass := 0
	p.Task("err2", nil, func(*do.Context) {
		if pass == 2 {
			do.Halt("oh oh")
		}
	})

	p.Task("err", do.S{"err2"}, func(*do.Context) {
		pass++
		if pass == 1 {
			return
		}
		do.Halt("foo err")
	}).Src("test/*.txt")

	p.Task("hello", nil, func(c *do.Context) {
		name := c.Args.AsString("default value", "name", "n")
		fmt.Println("Hello", name)
	}).Src("*.hello").Debounce(3000)

	p.Task("server", nil, func(c *do.Context) {
		c.Start("main.go", do.M{"$in": "cmd/example"})
	}).Src("cmd/example/**/*.go")

	p.Task("change-package", nil, func(c *do.Context) {
		// works on mac
		c.Run(`find . -name "*.go" -print | xargs sed -i "" 's|gopkg.in/godo.v1|gopkg.in/godo.v2|g'`)
		// maybe linux?
		//Run(`find . -name "*.go" -print | xargs sed -i 's|gopkg.in/godo.v1|gopkg.in/godo.v2|g'`)
	})
}
Пример #2
0
func tasks(p *do.Project) {
	p.Task("bench", nil, func(c *do.Context) {
		c.Run("LOGXI=* go test -bench . -benchmem", do.M{"$in": "v1/bench"})
	})

	p.Task("build", nil, func(c *do.Context) {
		c.Run("go build", do.M{"$in": "v1/cmd/demo"})
	})

	p.Task("linux-build", nil, func(c *do.Context) {
		c.Bash(`
			set -e
			GOOS=linux GOARCH=amd64 go build
			scp -F ~/projects/provision/matcherino/ssh.vagrant.config demo devmaster1:~/.
		`, do.M{"$in": "v1/cmd/demo"})
	})

	p.Task("etcd-set", nil, func(c *do.Context) {
		kv := c.Args.NonFlags()
		if len(kv) != 2 {
			do.Halt(fmt.Errorf("godo etcd-set -- KEY VALUE"))
		}

		c.Run(
			`curl -L http://127.0.0.1:4001/v2/keys/{{.key}} -XPUT -d value="{{.value}}"`,
			do.M{"key": kv[0], "value": kv[1]},
		)
	})

	p.Task("etcd-del", nil, func(c *do.Context) {
		kv := c.Args.Leftover()
		if len(kv) != 1 {
			do.Halt(fmt.Errorf("godo etcd-del -- KEY"))
		}
		c.Run(
			`curl -L http://127.0.0.1:4001/v2/keys/{{.key}} -XDELETE`,
			do.M{"key": kv[0]},
		)
	})

	p.Task("demo", nil, func(c *do.Context) {
		c.Run("go run main.go", do.M{"$in": "v1/cmd/demo"})
	})

	p.Task("demo2", nil, func(c *do.Context) {
		c.Run("go run main.go", do.M{"$in": "v1/cmd/demo2"})
	})

	p.Task("filter", do.S{"build"}, func(c *do.Context) {
		c.Run("go build", do.M{"$in": "v1/cmd/filter"})
		c.Bash("LOGXI=* ../demo/demo | ./filter", do.M{"$in": "v1/cmd/filter"})
	})

	p.Task("gifcast", do.S{"build"}, func(*do.Context) {
		commands := []pair{
			{
				`create a simple app demo`,
				`cat main.ansi`,
			},
			{
				`running demo displays only warnings and errors with context`,
				`demo`,
			},
			{
				`show all log levels`,
				`LOGXI=* demo`,
			},
			{
				`enable/disable loggers with level`,
				`LOGXI=*=ERR,models demo`,
			},
			{
				`create custom 256 colors colorscheme, pink==200`,
				`LOGXI_COLORS=*=black+h,ERR=200+b,key=blue+h demo`,
			},
			{
				`put keys on newline, set time format, less context`,
				`LOGXI=* LOGXI_FORMAT=pretty,maxcol=80,t=04:05.000,context=0 demo`,
			},
			{
				`logxi defaults to fast, unadorned JSON in production`,
				`demo | cat`,
			},
		}

		// setup time for ecorder, user presses enter when ready
		clear()
		do.Prompt("")

		intro(
			"log XI",
			"structured. faster. friendlier.\n\n\n\n\t::mgutz",
			1*time.Second,
		)

		for _, cmd := range commands {
			typeCommand(cmd.description, cmd.command)
			do.Bash(cmd.command, do.M{"$in": "v1/cmd/demo"})
			time.Sleep(3500 * time.Millisecond)
		}

		clear()
		do.Prompt("")
	})

	p.Task("demo-gif", nil, func(c *do.Context) {
		c.Bash(`cp ~/Desktop/demo.gif images`)
	})

	p.Task("bench-allocs", nil, func(c *do.Context) {
		c.Bash(`go test -bench . -benchmem -run=none | grep "allocs\|^Bench"`, do.M{"$in": "v1/bench"})
	}).Description("Runs benchmarks with allocs")

	p.Task("benchjson", nil, func(c *do.Context) {
		c.Bash("go test -bench=BenchmarkLoggerJSON -benchmem", do.M{"$in": "v1/bench"})
	})

	p.Task("test", nil, func(c *do.Context) {
		c.Run("LOGXI=* go test", do.M{"$in": "v1"})
		//Run("LOGXI=* go test -run=TestColors", M{"$in": "v1"})
	})

	p.Task("isolate", do.S{"build"}, func(c *do.Context) {
		c.Bash("LOGXI=* LOGXI_FORMAT=fit,maxcol=80,t=04:05.000,context=2 demo", do.M{"$in": "v1/cmd/demo"})
	})

	p.Task("install", nil, func(c *do.Context) {
		packages := []string{
			"github.com/mattn/go-colorable",
			"github.com/mattn/go-isatty",
			"github.com/mgutz/ansi",
			"github.com/stretchr/testify/assert",

			// needed for benchmarks in bench/
			"github.com/Sirupsen/logrus",
			"gopkg.in/inconshreveable/log15.v2",
		}
		for _, pkg := range packages {
			c.Run("go get -u " + pkg)
		}
	}).Description("Installs dependencies")

}