summaryrefslogtreecommitdiff
path: root/unix.go
blob: 94a722f88570672e3c08f1175bd025adf9c35785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// This is a simple example
package main

import 	(
	"os"
	"os/exec"
	"strings"

	"go.wit.com/log"

//	"go.wit.com/gui/gui"
//	"go.wit.com/gui/gadgets"
//	"go.wit.com/apps/control-panel-dns/smartwindow"
)

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 ""
	}

	// Print the output
	log.Info(string(output))
	return string(output)
}

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
}