MIT License

项目介绍

go-godo/godo 是一个托管在 GitHub 上的开源项目,主要使用 Go 编写,采用 MIT License 许可证,目前获得 530 个 Star、30 次 Fork。

仓库全名
go-godo/godo
开源许可证
MIT License
Star 数
530
Fork 数
30
未关闭 Issue
21

README 摘要

godo godoc godo is a task runner and file watcher for golang in the spirit of rake, gulp. To install go get -u gopkg.in/godo.v1/cmd/godo Godofile godo runs either Gododir/Godofile.go or tasks/Godofile.go. As an example, create a file Gododir/Godofile.go with this content To run "server" task from parent dir of tasks/ godo server To rerun "server" and its dependencies whenever any of their watched files change godo…

完整内容见 GitHub 原始 README 或本页 。

常见问题

godo 用什么语言开发?

主要使用 Go 编写,采用 MIT License 许可证,目前有 530 个 Star。

godo 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 godo 的源码?

可以直接克隆仓库:git clone https://github.com/go-godo/godo.git,默认分支为 v2;安装与运行步骤见仓库 README。

godo 最近还在维护吗?

仓库最近一次更新为 2018年4月25日,当前有 21 个未关闭 Issue;Star 数为 530,可作为社区活跃度的参考。

关于

golang build tool in the spirt of rake, gulp

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
603
价值分
327
活跃状态
活跃

语言占比

Batchfile
Go
Makefile
Shell

Release

README

godo

godoc

godo is a task runner and file watcher for golang in the spirit of rake, gulp.

To install

go get -u gopkg.in/godo.v1/cmd/godo

Godofile

godo runs either Gododir/Godofile.go or tasks/Godofile.go.

As an example, create a file Gododir/Godofile.go with this content

package main

import (
	"fmt"
    . "gopkg.in/godo.v1"
)

func tasks(p *Project) {
    Env = `GOPATH=.vendor::$GOPATH`

    p.Task("default", D{"hello", "build"})

    p.Task("hello", func(c *Context) {
        name := c.Args.ZeroString("name", "n")
        if name == "" {
            Bash("echo Hello $USER!")
        } else {
            fmt.Println("Hello", name)
        }
    })

    p.Task("assets?", func() {
        // The "?" tells Godo to run this task ONLY ONCE regardless of
        // how many tasks depend on it. In this case watchify watches
        // on its own.
		Run("watchify public/js/index.js d -o dist/js/app.bundle.js")
    }).Watch("public/**/*.{css,js,html}")

    p.Task("build", D{"views", "assets"}, func() error {
        return Run("GOOS=linux GOARCH=amd64 go build", In{"cmd/server"})
    }).Watch("**/*.go")

    p.Task("server", D{"views", "assets"}, func() {
        // rebuilds and restarts when a watched file changes
        Start("main.go", M{"$in": "cmd/server"})
    }).Watch("server/**/*.go", "cmd/server/*.{go,json}").
       Debounce(3000)

    p.Task("views", func() error {
        return Run("razor templates")
    }).Watch("templates/**/*.go.html")
}

func main() {
    Godo(tasks)
}

To run “server” task from parent dir of tasks/

godo server

To rerun “server” and its dependencies whenever any of their watched files change

godo server --watch

To run the “default” task which runs “hello” and “build”

godo

Task names may add a “?” suffix to execute only once even when watching

// build once regardless of number of dependents
p.Task("assets?", func() {})

Task options

D{} or Dependencies{} - dependent tasks which run before task
W{} or Watches{}      - array of glob file patterns to watch

    /**/   - match zero or more directories
    {a,b}  - match a or b, no spaces
    *      - match any non-separator char
    ?      - match a single non-separator char
    **/    - match any directory, start of pattern only
    /**    - match any in this directory, end of pattern only
    !      - removes files from result set, start of pattern only

Task handlers

func()                  - Simple function handler, don't care about return
func() error            - Simple function handler
func(c *Context)        - Task with context, don't care about return
func(c *Context) error  - Task with context

Any error return in task or its dependencies stops the pipeline and godo exits with status code of 1, except in watch mode.

Task Arguments

Task arguments follow POSIX style flag convention (unlike go’s built-in flag package). Any command line arguments succeeding -- are passed to each task. Note, arguments before -- are reserved for godo.

As an example,

p.Task("hello", func(c *Context) {
    // "(none)" is the default value
    msg := c.Args.MayString("(none)", "message", "msg", "m")
    var name string
    if len(c.Args.Leftover() == 1) {
        name = c.Args.Leftover()[0]
    }
    fmt.Println(msg, name)
})

running

# prints "(none)"
godo hello

# prints "Hello dude" using POSIX style flags
godo hello -- dude --message Hello
godo hello -- dude --msg Hello
godo hello -- -m Hello dude

Args functions are categorized as

  • Must* - Argument must be set by user or panic.

c.Args.MustInt(“number”, “n”)


*  `May*` - If argument is not set, default to first value.

    ```go
    // defaults to 100
    c.Args.MayInt(100, "number", "n")
  • Zero* - If argument is not set, default to zero value.

// defaults to 0 c.Args.ZeroInt(“number”, “n”)


## godobin

`godo` compiles `Godofile.go` to `godobin-VERSION` (`godobin-VERSION.exe` on Windows) whenever
`Godofile.go` changes. The binary file is built into the same directory as
`Godofile.go` and should be ignored by adding the path `godobin*` to `.gitignore`.

## Exec functions

All of these functions accept a `map[string]interface{}` or `M` for
options. Option keys that start with `"$"` are reserved for `godo`.
Other fields can be used as context for template.

### Bash

Bash functions uses the bash executable and may not run on all OS.

Run a bash script string. The script can be multiline line with continutation.

```go
Bash(`
    echo -n $USER
    echo some really long \
        command
`)

Bash can use Go templates

Bash(`echo -n {{.name}}`, M{"name": "mario", "$in": "cmd/bar"})

Run a bash script and capture STDOUT and STDERR.

output, err := BashOutput(`echo -n $USER`)

Run

Run go build inside of cmd/app and set environment variables.

Run(`GOOS=linux GOARCH=amd64 go build`, M{"$in": "cmd/app"})

Run can use Go templates

Run(`echo -n {{.name}}`, M{"name": "mario", "$in": "cmd/app"})

Run and capture STDOUT and STDERR

output, err := RunOutput("whoami")

Start

Start an async command. If the executable has suffix “.go” then it will be "go install"ed then executed. Use this for watching a server task.

Start("main.go", M{"$in": "cmd/app"})

Godo tracks the process ID of started processes in the map Processes to restart the app gracefully.

If Start is not working as expected with go files, verify go install -a main.go works in the directory of the file, replacing “main.go” with your file. Most issues around (re)starts are due to being outside of GOPATH or multiple packages in a directory. Set Env if GOPATH needs to be adjusted.

Inside

To run many commands inside a directory, use Inside instead of the $in option. Inside changes the working directory.

Inside("somedir", func() {
    Run("...")
    Bash("...")
})

User Input

To get plain string

user := Prompt("user: ")

To get password

password := PromptPassword("password: ")

Godofile Run-Time Environment

To specify whether to inherit from parent’s process environment, set InheritParentEnv. This setting defaults to true

InheritParentEnv = false

To specify the base environment for your tasks, set Env. Separate with whitespace or newlines.

Env = `
    GOPATH=.vendor::$GOPATH
    PG_USER=mario
`

TIP: Set the Env when using a dependency manager like godep

wd, _ := os.Getwd()
ws := path.Join(wd, "Godeps/_workspace")
Env = fmt.Sprintf("GOPATH=%s::$GOPATH", ws)

Functions can add or override environment variables as part of the command string. Note that environment variables are set before the executable similar to a shell; however, the Run and Start functions do not use a shell.

p.Task("build", func() {
    Run("GOOS=linux GOARCH=amd64 go build" )
})

The effective environment for exec functions is: parent (if inherited) <- Env <- func parsed env

Paths should use :: as a cross-platform path list separator. On Windows :: is replaced with ;. On Mac and linux :: is replaced with :.

评论

暂无评论