-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
61 lines (53 loc) · 1.17 KB
/
commands.go
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
56
57
58
59
60
61
package main
import (
"github.com/charmbracelet/log"
"os"
"os/exec"
"strings"
)
const (
InstallFrontendDependencies = "npm install"
LaunchDevServer = "npm run dev"
BuildFrontend = "npm run build"
CompileBackend = "mvn clean compile"
BundleApp = "mvn compile assembly:single"
LaunchApp = "mvn exec:java"
GenerateAppBinds = "mvn exec:java -Dexec.args=\"generate\""
)
type Opt = func(cmd *exec.Cmd)
func WithStdout(cmd *exec.Cmd) {
cmd.Stdout = os.Stdout
}
func WithStderr(cmd *exec.Cmd) {
cmd.Stderr = os.Stderr
}
type CmdProps struct {
Cmd string
LogBefore string
Sync bool
Opts []Opt
}
func Opts(opts ...Opt) []Opt {
var ropts []Opt
for _, o := range opts {
ropts = append(ropts, o)
}
return ropts
}
func RunCommand(props CmdProps) (*exec.Cmd, error) {
words := strings.Split(props.Cmd, " ")
name := words[0]
args := words[1:]
command := exec.Command(name, args...)
for _, opt := range props.Opts {
opt(command)
}
var err error = nil
log.Info(props.LogBefore)
if props.Sync {
err = command.Run()
} else {
err = command.Start()
}
return command, err
}