2016-04-05 16:59:52 -05:00
|
|
|
// Copyright 2016 Tim Shannon. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2016-04-20 08:38:53 -05:00
|
|
|
func runCmd(cmd, dir string, env []string) ([]byte, error) {
|
2016-04-20 10:40:07 -05:00
|
|
|
s := strings.Fields(strings.Replace(cmd, "@dir", dir, -1))
|
2016-04-05 16:59:52 -05:00
|
|
|
|
2016-04-20 08:38:53 -05:00
|
|
|
for i := range env {
|
|
|
|
env[i] = strings.Replace(env[i], "@dir", dir, -1)
|
|
|
|
}
|
|
|
|
|
2016-04-05 16:59:52 -05:00
|
|
|
var args []string
|
|
|
|
|
|
|
|
if len(s) > 1 {
|
|
|
|
args = s[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
ec := exec.Command(s[0], args...)
|
|
|
|
|
|
|
|
ec.Dir = dir
|
2016-04-20 08:38:53 -05:00
|
|
|
ec.Env = env
|
2016-04-05 16:59:52 -05:00
|
|
|
|
|
|
|
vlog("Executing command: %s in dir %s\n", cmd, dir)
|
|
|
|
|
|
|
|
result, err := ec.CombinedOutput()
|
|
|
|
if err != nil {
|
2016-04-14 11:29:56 -05:00
|
|
|
return nil, fmt.Errorf("%s", result)
|
2016-04-05 16:59:52 -05:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|