diff options
| author | Jeff Carr <[email protected]> | 2024-01-09 15:34:53 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-09 15:34:53 -0600 |
| commit | 87346d9452b38db517e76e070f11928060bc2b99 (patch) | |
| tree | 2e6ff93e368fda0a1581496985798fe4c1de3569 /unix.go | |
initial commit
Diffstat (limited to 'unix.go')
| -rw-r--r-- | unix.go | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -0,0 +1,54 @@ +// 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 +} |
