-
Notifications
You must be signed in to change notification settings - Fork 19
/
util.go
28 lines (24 loc) · 584 Bytes
/
util.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
package demo
import (
"fmt"
"os/exec"
)
// Ensure executes the provided commands in order.
// This utility function can be used during setup or cleanup.
func Ensure(commands ...string) error {
for _, c := range commands {
cmd := exec.Command("sh", "-c", c)
cmd.Stderr = nil
cmd.Stdout = nil
if err := cmd.Run(); err != nil {
return fmt.Errorf("run command: %w", err)
}
}
return nil
}
// MustEnsure executes the provided commands in order and panics on failure.
func MustEnsure(commands ...string) {
if err := Ensure(commands...); err != nil {
panic(err)
}
}