// Start starts an async command. If executable has suffix ".go" then it will // be "go install"ed then executed. Use this for watching a server task. // // If Start is called with the same command it kills the previous process. // // The working directory is optional. func Start(commandstr string, options ...map[string]interface{}) error { m, dir, _, err := parseOptions(options) if err != nil { return err } if strings.Contains(commandstr, "{{") { commandstr, err = util.StrTemplate(commandstr, m) if err != nil { return err } } executable, argv, env := splitCommand(commandstr) isGoFile := strings.HasSuffix(executable, ".go") if isGoFile { _, err = Run("go install -a", m) if err != nil { return err } executable = filepath.Base(dir) } cmd := &command{ executable: executable, wd: dir, env: env, argv: argv, commandstr: commandstr, } return cmd.runAsync() }
func generateTasks(p *do.Project) { p.Task("builder-boilerplate", nil, func(c *do.Context) { context := do.M{ "builders": []string{"CallBuilder", "DeleteBuilder", "InsectBuilder", "InsertBuilder", "RawBuilder", "SelectBuilder", "SelectDocBuilder", "UpdateBuilder", "UpsertBuilder"}, } s, err := util.StrTemplate(builderTemplate, context) c.Check(err, "Unalbe ") ioutil.WriteFile("builders_generated.go", []byte(s), 0644) c.Run("go fmt builders_generated.go") }).Desc("Generates builder boilerplate code") }
func run(commandstr string, options []map[string]interface{}) (output string, err error) { m, dir, capture, err := parseOptions(options) if err != nil { return "", err } if strings.Contains(commandstr, "{{") { commandstr, err = util.StrTemplate(commandstr, m) if err != nil { return "", err } } lines := strings.Split(commandstr, "\n") if len(lines) == 0 { return "", fmt.Errorf("Empty command string") } for i, cmdline := range lines { cmdstr := strings.Trim(cmdline, " \t") if cmdstr == "" { continue } executable, argv, env := splitCommand(cmdstr) cmd := &command{ executable: executable, wd: dir, env: env, argv: argv, capture: capture, commandstr: commandstr, } s, err := cmd.run() if err != nil { err = fmt.Errorf(err.Error()+"\nline=%d", i) return s, err } output += s } return output, nil }
// Bash executes a bash string. Use backticks for multiline. To execute as shell script, // use Run("bash script.sh") func bash(script string, options []map[string]interface{}) (output string, err error) { m, dir, capture, err := parseOptions(options) if err != nil { return "", err } if strings.Contains(script, "{{") { script, err = util.StrTemplate(script, m) if err != nil { return "", err } } gcmd := &command{ executable: "bash", argv: []string{"-c", script}, wd: dir, capture: capture, commandstr: script, } return gcmd.run() }