Пример #1
0
func run(captureOutput bool, commandstr string, options []interface{}) (output string, err error) {
	m := getOptionsMap(options)
	dir, err := getWorkingDir(m)
	if err != nil {
		return
	}

	if strings.Contains(commandstr, "{{") {
		commandstr, err = util.StrTemplate(commandstr, m)
		if err != nil {
			return "", err
		}
	}

	executable, argv, env := splitCommand(commandstr)

	cmd := &command{
		executable:    executable,
		wd:            dir,
		env:           env,
		argv:          argv,
		captureOutput: captureOutput,
		commandstr:    commandstr,
	}

	s, err := cmd.run()
	return s, err
}
Пример #2
0
// 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 ...interface{}) error {
	m := getOptionsMap(options)
	dir, err := getWorkingDir(m)
	if err != nil {
		return nil
	}

	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", options...)
		if err != nil {
			return err
		}
		executable = filepath.Base(dir)
	}

	cmd := &command{
		executable: executable,
		wd:         dir,
		env:        env,
		argv:       argv,
		commandstr: commandstr,
	}
	return cmd.runAsync()
}
Пример #3
0
// Bash executes a bash string. Use backticks for multiline. To execute as shell script,
// use Run("bash script.sh")
func bash(captureOutput bool, script string, options []interface{}) (output string, err error) {
	m := getOptionsMap(options)
	dir, err := getWorkingDir(m)
	if err != nil {
		return
	}

	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,
		captureOutput: captureOutput,
		commandstr:    script,
	}

	return gcmd.run()
}