在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):go-godo/godo开源软件地址(OpenSource Url):https://github.com/go-godo/godo开源编程语言(OpenSource Language):Go 100.0%开源软件介绍(OpenSource Introduction):Documentation is WIP godogodo is a task runner and file watcher for golang in the spirit of rake, gulp. To install
GodofileGodo runs As an example, create a file Gododir/main.go with this content package main
import (
"fmt"
do "gopkg.in/godo.v2"
)
func tasks(p *do.Project) {
do.Env = `GOPATH=.vendor::$GOPATH`
p.Task("default", do.S{"hello", "build"}, nil)
p.Task("hello", nil, func(c *do.Context) {
name := c.Args.AsString("name", "n")
if name == "" {
c.Bash("echo Hello $USER!")
} else {
fmt.Println("Hello", name)
}
})
p.Task("assets?", nil, func(c *do.Context) {
// 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.
c.Run("watchify public/js/index.js d -o dist/js/app.bundle.js")
}).Src("public/**/*.{css,js,html}")
p.Task("build", do.S{"views", "assets"}, func(c *do.Context) {
c.Run("GOOS=linux GOARCH=amd64 go build", do.M{"$in": "cmd/server"})
}).Src("**/*.go")
p.Task("server", do.S{"views", "assets"}, func(c *do.Context) {
// rebuilds and restarts when a watched file changes
c.Start("main.go", do.M{"$in": "cmd/server"})
}).Src("server/**/*.go", "cmd/server/*.{go,json}").
Debounce(3000)
p.Task("views", nil, func(c *do.Context) {
c.Run("razor templates")
}).Src("templates/**/*.go.html")
}
func main() {
do.Godo(tasks)
} To run "server" task from parent dir of
To rerun "server" and its dependencies whenever any of their watched files change
To run the "default" task which runs "hello" and "build"
Task names may add a "?" suffix to execute only once even when watching // build once regardless of number of dependents
p.Task("assets?", nil, func(*do.Context) { }) Task dependencies
Task Option Funcs
Task CLI ArgumentsTask CLI arguments follow POSIX style flag convention
(unlike go's built-in flag package). Any command line arguments
succeeding As an example, p.Task("hello", nil, func(c *do.Context) {
// "(none)" is the default value
msg := c.Args.MayString("(none)", "message", "msg", "m")
var name string
if len(c.Args.NonFlags()) == 1 {
name = c.Args.NonFlags()[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
c.Args.MustInt("number", "n")
// defaults to 0 c.Args.AsInt("number", "n")
Running The special name Task dependencies that start with godobin
Exec functionsAll of these functions accept a BashBash 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. c.Bash(`
echo -n $USER
echo some really long \
command
`) Bash can use Go templates c.Bash(`echo -n {{.name}}`, do.M{"name": "mario", "$in": "cmd/bar"}) Run a bash script and capture STDOUT and STDERR. output, err := c.BashOutput(`echo -n $USER`) RunRun c.Run(`GOOS=linux GOARCH=amd64 go build`, do.M{"$in": "cmd/app"}) Run can use Go templates c.Run(`echo -n {{.name}}`, do.M{"name": "mario", "$in": "cmd/app"}) Run and capture STDOUT and STDERR output, err := c.RunOutput("whoami") StartStart 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. c.Start("main.go", do.M{"$in": "cmd/app"}) Godo tracks the process ID of started processes to restart the app gracefully. InsideTo run many commands inside a directory, use do.Inside("somedir", func() {
do.Run("...")
do.Bash("...")
}) User InputTo get plain string user := do.Prompt("user: ") To get password password := do.PromptPassword("password: ") Godofile Run-Time EnvironmentFrom command-lineEnvironment variables may be set via key-value pairs as arguments to godo. This feature was added to facilitate users on Windows. godo NAME=mario GOPATH=./vendor hello From source codeTo specify whether to inherit from parent's process environment,
set do.InheritParentEnv = false To specify the base environment for your tasks, set do.Env = `
GOPATH=.vendor::$GOPATH
PG_USER=mario
` 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 p.Task("build", nil, func(c *do.Context) {
c.Run("GOOS=linux GOARCH=amd64 go build" )
}) The effective environment for exec functions is: Paths should use From godoenv fileFor special circumstances where the GOPATH needs to be set before building the Gododir,
use TIP: Create
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论