55 lines
956 B
Go
55 lines
956 B
Go
|
// This is a simple example
|
||
|
package repostatus
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"strings"
|
||
|
|
||
|
"go.wit.com/log"
|
||
|
)
|
||
|
|
||
|
func fullpath(repo string) string {
|
||
|
return "/home/jcarr/go/src/" + repo
|
||
|
}
|
||
|
|
||
|
func run(path string, thing string, cmdline string) string {
|
||
|
parts := strings.Split(cmdline, " ")
|
||
|
// Create the command
|
||
|
cmd := exec.Command(thing, parts...)
|
||
|
|
||
|
// Set the working directory
|
||
|
cmd.Dir = fullpath(path)
|
||
|
|
||
|
// Execute the command
|
||
|
output, err := cmd.CombinedOutput()
|
||
|
if err != nil {
|
||
|
log.Error(err, "cmd error'd out", parts)
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
tmp := string(output)
|
||
|
tmp = strings.TrimSpace(tmp)
|
||
|
|
||
|
// Print the output
|
||
|
log.Log(WARN, "run()", path, thing, cmdline, "=", tmp)
|
||
|
return tmp
|
||
|
}
|
||
|
|
||
|
func listFiles(directory string) []string {
|
||
|
var files []string
|
||
|
fileInfo, err := os.ReadDir(directory)
|
||
|
if err != nil {
|
||
|
log.Error(err)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
for _, file := range fileInfo {
|
||
|
if !file.IsDir() {
|
||
|
files = append(files, file.Name())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return files
|
||
|
}
|