package utils import ( "bytes" "fmt" "os/exec" "github.com/hashicorp/hcl/v2" ) var DryRun = false func CheckErr(e error) { if e != nil { panic(e) } } func CheckDiags(diag hcl.Diagnostics) { if diag.HasErrors() { panic(diag.Error()) } } // Execute a system command ... func RunSystemCommand(name string, arg ...string) ([]byte, []byte, error) { if DryRun { stdOut := []byte(fmt.Sprintf("CMD %s\n", name)) stdErr := []byte("STDERR\n") return stdOut, stdErr, nil } else { var stdOut bytes.Buffer var stdErr bytes.Buffer cmd := exec.Command(name, arg...) cmd.Stderr = &stdErr cmd.Stdout = &stdOut err := cmd.Run() return stdOut.Bytes(), stdErr.Bytes(), err } }