diff --git a/src/assertions.rs b/src/assertions.rs
index f33b31d..2cd6989 100644
--- a/src/assertions.rs
+++ b/src/assertions.rs
@@ -288,6 +288,9 @@ impl std::fmt::Display for Git {
impl AssertionType for Git {
fn status(&self) -> Result<Status> {
+ // First, ensure git binary is available
+ Utils::assert_bin("git")?;
+
let dir_path = Path::new(&self.dir);
// Check if directory exists
@@ -341,6 +344,9 @@ impl AssertionType for Git {
}
fn install(&self) -> Result<()> {
+ // Ensure git binary is available before attempting clone
+ Utils::assert_bin("git")?;
+
let (_output, exit_code) = Utils::sh(
"git",
&[
diff --git a/src/lib.rs b/src/lib.rs
index e3c1930..08a4294 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,3 @@
pub mod assertions;
pub mod errors;
pub mod utils;
-
diff --git a/src/main.rs b/src/main.rs
index c775b00..cc2c7c6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,8 +3,8 @@ mod errors;
mod utils;
use assertions::{
- AssertionType, AssertionTypeFactory, Debug, Directory, Git, LuaAssertion, LuaAssertionType, Status,
- Symlink, TypedFactory,
+ AssertionType, AssertionTypeFactory, Debug, Directory, Git, LuaAssertion, LuaAssertionType,
+ Status, Symlink, TypedFactory,
};
use clap::{Parser, Subcommand};
use color_eyre::{Result, eyre::eyre};
diff --git a/src/utils.rs b/src/utils.rs
index cb8cbdd..b864998 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -163,6 +163,18 @@ impl Utils {
);
Ok((stdout, status))
}
+
+ pub fn assert_bin(bin_name: &str) -> Result<()> {
+ // Use 'which' command to check if binary exists in PATH
+ let (_output, exit_code) = Self::sh("which", &[bin_name.to_string()])?;
+
+ if exit_code == 0 {
+ debug!("Binary '{}' found in PATH", bin_name);
+ Ok(())
+ } else {
+ Err(eyre!("Required binary '{}' not found in PATH", bin_name))
+ }
+ }
}
impl IntoLua for Utils {
@@ -170,7 +182,7 @@ impl IntoLua for Utils {
let utils_table = lua.create_table()?;
utils_table.set(
- "expand_path",
+ "expand-path",
lua.create_function(|_lua, path: String| {
Utils::expand_path(&path).map_err(LuaError::external)
})?,
@@ -220,6 +232,12 @@ impl IntoLua for Utils {
.map_err(LuaError::external)
})?,
)?;
+ utils_table.set(
+ "assert-bin",
+ lua.create_function(|_lua, bin_name: String| {
+ Utils::assert_bin(&bin_name).map_err(LuaError::external)
+ })?,
+ )?;
Ok(LuaValue::Table(utils_table))
}