From 097f8670eb2e5c49a36dcf399e59f4057007b5b1 Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Tue, 15 Oct 2024 10:35:09 -0500 Subject: Fail immediately when commands missing --- internal/exec.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 internal/exec.go (limited to 'internal/exec.go') diff --git a/internal/exec.go b/internal/exec.go new file mode 100644 index 0000000..6ed3e5c --- /dev/null +++ b/internal/exec.go @@ -0,0 +1,21 @@ +package internal + +import ( + "fmt" + "os/exec" +) + +type CommandNotFound string + +func (e CommandNotFound) Error() string { + return fmt.Sprintf("command '%s' is missing and must be present for operation", string(e)) +} + +func RequireCommand(cmd string) error { + _, err := exec.LookPath(cmd) + if err != nil { + return CommandNotFound(cmd) + } + + return nil +} -- cgit v1.2.3