all repos — vite @ c6535b7c59b827e8ff6b172a8779996ef7ee32be

a fast (this time, actually) and minimal static site generator

util/run.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
package util

import (
	"fmt"
	"os/exec"
	"strings"
)

func RunCmd(cmd string, args ...string) error {
	// Split the command into the executable and its arguments
	parts := strings.Fields(cmd)
	if len(parts) == 0 {
		return fmt.Errorf("error: is there an empty command?")
	}

	execCmd := exec.Command(parts[0], parts[1:]...)

	output, err := execCmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("error: command %q failed with %v: %s", cmd, err, output)
	}
	return nil
}