fmt
change yoowzrmsozormkrnuqtyvprwlmqsupkq
commit 2d323eedb3dab099e68854ad2e8a05a9e98bfb9d
author Alpha Chen <alpha@kejadlen.dev>
date
parent qstmnsol
diff --git a/frork-cli/src/assertions.rs b/frork-cli/src/assertions.rs
index 9fce112..74ff5be 100644
--- a/frork-cli/src/assertions.rs
+++ b/frork-cli/src/assertions.rs
@@ -342,13 +342,7 @@ impl AssertionType for Git {
         // Check if we can get the git remote
         let (remote_output, exit_code) = Utils::sh(
             "git",
-            &[
-                "-C".to_string(),
-                self.dir.to_string(),
-                "config".to_string(),
-                "--get".to_string(),
-                "remote.origin.url".to_string(),
-            ],
+            &["-C", &self.dir, "config", "--get", "remote.origin.url"],
         )?;
 
         if exit_code != 0 {
@@ -373,14 +367,7 @@ impl AssertionType for Git {
         // Ensure git binary is available before attempting clone
         Utils::assert_bin("git")?;
 
-        let (_output, exit_code) = Utils::sh(
-            "git",
-            &[
-                "clone".to_string(),
-                self.remote_url.clone(),
-                self.dir.to_string(),
-            ],
-        )?;
+        let (_output, exit_code) = Utils::sh("git", &["clone", &self.remote_url, &self.dir])?;
 
         if exit_code != 0 {
             return Err(eyre!("Failed to clone git repository"));
@@ -490,7 +477,7 @@ impl AssertionType for Brew {
             return Ok(Status::Missing);
         }
 
-        let (_output, exit_code) = Utils::sh("brew", &["--version".to_string()])?;
+        let (_output, exit_code) = Utils::sh("brew", &["--version"])?;
         if exit_code == 0 {
             Ok(Status::Ok)
         } else {
@@ -498,17 +485,18 @@ impl AssertionType for Brew {
         }
     }
 
+    // This needs sudo - figure out how to make this work through frork
     fn install(&self) -> Result<()> {
-        let (_output, exit_code) = Utils::sh(
+        let (output, exit_code) = Utils::sh(
             "bash",
             &[
-                "-c".to_string(),
-                r#"/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)""#.to_string(),
+                "-c",
+                r#"/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)""#,
             ],
         )?;
 
         if exit_code != 0 {
-            return Err(eyre!("Failed to install Homebrew"));
+            return Err(eyre!("Failed to install Homebrew: {}", output));
         }
 
         debug!("installed: {}", self);
@@ -551,14 +539,10 @@ impl AssertionType for BrewBundle {
         Utils::assert_bin("brew")?;
 
         // First check: brew bundle check --no-upgrade
+        let file_arg = format!("--file={}", self.brewfile);
         let (_output, exit_code) = Utils::sh_with_envs(
             "brew",
-            &[
-                "bundle".to_string(),
-                "check".to_string(),
-                "--no-upgrade".to_string(),
-                format!("--file={}", self.brewfile),
-            ],
+            &["bundle", "check", "--no-upgrade", &file_arg],
             &[("HOMEBREW_NO_AUTO_UPDATE", "true")],
         )?;
 
@@ -567,13 +551,10 @@ impl AssertionType for BrewBundle {
         }
 
         // Second check: brew bundle check (without --no-upgrade)
+        let file_arg = format!("--file={}", self.brewfile);
         let (_output, exit_code) = Utils::sh_with_envs(
             "brew",
-            &[
-                "bundle".to_string(),
-                "check".to_string(),
-                format!("--file={}", self.brewfile),
-            ],
+            &["bundle", "check", &file_arg],
             &[("HOMEBREW_NO_AUTO_UPDATE", "true")],
         )?;
 
@@ -595,14 +576,8 @@ impl AssertionType for BrewBundle {
         // Assert brew binary exists
         Utils::assert_bin("brew")?;
 
-        let (_output, exit_code) = Utils::sh(
-            "brew",
-            &[
-                "bundle".to_string(),
-                "install".to_string(),
-                format!("--file={}", self.brewfile),
-            ],
-        )?;
+        let file_arg = format!("--file={}", self.brewfile);
+        let (_output, exit_code) = Utils::sh("brew", &["bundle", "install", &file_arg])?;
 
         if exit_code != 0 {
             return Err(eyre!("Failed to install brew bundle"));
diff --git a/frork-cli/src/utils.rs b/frork-cli/src/utils.rs
index 558f8f6..c08ae68 100644
--- a/frork-cli/src/utils.rs
+++ b/frork-cli/src/utils.rs
@@ -140,26 +140,29 @@ impl Utils {
     }
 
     pub fn platform() -> Result<String> {
-        let (output, _status) = Self::sh("uname", &["-s".to_string()])?;
+        let (output, _status) = Self::sh("uname", &["-s"])?;
         Ok(Self::chomp(&output).to_lowercase())
     }
 
-    pub fn sh(cmd: &str, args: &[String]) -> Result<(String, i32)> {
+    pub fn sh<T: AsRef<str>>(cmd: &str, args: &[T]) -> Result<(String, i32)> {
         Self::sh_with_envs(cmd, args, &[])
     }
 
-    pub fn sh_with_envs(
+    pub fn sh_with_envs<T: AsRef<str>>(
         cmd: &str,
-        args: &[String],
+        args: &[T],
         env_vars: &[(&str, &str)],
     ) -> Result<(String, i32)> {
+        let args_display: Vec<&str> = args.iter().map(|arg| arg.as_ref()).collect();
         debug!(
-            "Executing command: {} with args: {:?} and envs: {:?}",
-            cmd, args, env_vars
+            "Executing command: {} with args: {} and envs: {:?}",
+            cmd,
+            args_display.join(" "),
+            env_vars
         );
 
         let mut command = Command::new(cmd);
-        command.args(args);
+        command.args(args.iter().map(|arg| arg.as_ref()));
         command.envs(env_vars.iter().map(|(k, v)| (*k, *v)));
 
         let output = command
@@ -172,15 +175,17 @@ impl Utils {
             .code()
             .ok_or_else(|| eyre!("Command '{}' terminated by signal", cmd))?;
         debug!(
-            "Command '{}' completed with status {}, stdout: {:?}",
-            cmd, status, stdout
+            "Command '{}' completed with status {}, stdout: {}",
+            cmd,
+            status,
+            stdout.trim()
         );
         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()])?;
+        let (_output, exit_code) = Self::sh("which", &[bin_name])?;
 
         if exit_code == 0 {
             debug!("Binary '{}' found in PATH", bin_name);
diff --git a/frork-lib/src/lib.rs b/frork-lib/src/lib.rs
index e69de29..8b13789 100644
--- a/frork-lib/src/lib.rs
+++ b/frork-lib/src/lib.rs
@@ -0,0 +1 @@
+