shell/linux/utils.go
2024-07-04 16:40:13 -04:00

37 lines
671 B
Go

package linux
import (
"errors"
"fmt"
"os/exec"
)
func (cmd *LinuxCommand) doesCommandExist(command string) (bool, error) {
shellCmd := exec.Command(cmd.Options.Shell, "-c", fmt.Sprintf("command -v %s", command))
if err := shellCmd.Start(); err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr.ExitCode() == 1 {
return false, nil
} else {
return false, ErrRunningCmd
}
}
}
if err := shellCmd.Wait(); err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr.ExitCode() == 1 {
return false, nil
} else {
return false, ErrRunningCmd
}
}
}
return true, nil
}