1use std::ffi::OsStr;
2use std::fmt::Debug;
3use std::path::PathBuf;
4use std::process::Command;
5
6use crate::error::InstallationError;
7
8pub(crate) fn exec<S: AsRef<OsStr> + Debug>(
9 binary: &PathBuf,
10 argv: &[S],
11) -> Result<String, InstallationError> {
12 let output = Command::new(binary).args(argv).output()?.stdout;
13
14 Ok(String::from_utf8_lossy(&output).trim().to_string())
15}
16
17#[doc(hidden)]
18#[macro_export]
19macro_rules! implement_from_for_enum {
20 ($type:ty, $error:ty, $field:ident) => {
21 impl From<$type> for $error {
22 fn from(value: $type) -> Self {
23 <$error>::$field(value)
24 }
25 }
26 };
27}