package util

import (
	"fmt"
	"os/exec"
)

// Run executes a command and returns combined output or error.
func Run(cmd string, args ...string) error {
	c := exec.Command(cmd, args...)
	c.Stdout = nil
	c.Stderr = nil
	return c.Run()
}

// RunLogged returns stdout/stderr for logging while failing on error.
func RunLogged(cmd string, args ...string) (string, error) {
	c := exec.Command(cmd, args...)
	out, err := c.CombinedOutput()
	if err != nil {
		return string(out), fmt.Errorf("%s %v failed: %w: %s", cmd, args, err, string(out))
	}
	return string(out), nil
}
