use std::process::Command;
use crate::config::{Result, TestbedError};
pub fn install_mise() -> Result<()> {
let status = Command::new("sh")
.args(["-c", "curl -fsSL https://mise.run | sh"])
.status()
.map_err(|e| TestbedError::Qcow2Error {
message: format!("spawning mise installer: {e}"),
})?;
if !status.success() {
return Err(TestbedError::Qcow2Error {
message: "mise installer failed".to_string(),
});
}
if let Some(home) = dirs::home_dir() {
let mise_bin = home.join(".local").join("bin").join("mise");
if mise_bin.exists() {
let _ = mise_bin;
}
}
Ok(())
}
pub fn install_nushell() -> Result<()> {
let mise_bin = find_mise_bin()?;
let status = Command::new(&mise_bin)
.args(["install", "nu@latest"])
.env("MISE_CARGO_BINSTALL", "true")
.status()
.map_err(|e| TestbedError::Qcow2Error {
message: format!("mise install nu: {e}"),
})?;
if !status.success() {
return Err(TestbedError::Qcow2Error {
message: "failed to install nushell via mise".to_string(),
});
}
Ok(())
}
pub fn install_pitchfork() -> Result<()> {
let mise_bin = find_mise_bin()?;
let status = Command::new(&mise_bin)
.args(["install", "pitchfork@latest"])
.env("MISE_CARGO_BINSTALL", "true")
.status()
.map_err(|e| TestbedError::Qcow2Error {
message: format!("mise install pitchfork: {e}"),
})?;
if !status.success() {
eprintln!(" pitchfork not available via mise, trying cargo install...");
install_pitchfork_cargo()
} else {
Ok(())
}
}
fn install_pitchfork_cargo() -> Result<()> {
let status = Command::new("cargo")
.args(["install", "pitchfork"])
.status()
.map_err(|e| TestbedError::Qcow2Error {
message: format!("cargo install pitchfork: {e}"),
})?;
if !status.success() {
return Err(TestbedError::Qcow2Error {
message: "failed to install pitchfork".to_string(),
});
}
Ok(())
}
pub fn find_mise_bin() -> Result<std::path::PathBuf> {
if let Ok(p) = which::which("mise") {
return Ok(p);
}
if let Some(home) = dirs::home_dir() {
let bin = home.join(".local").join("bin").join("mise");
if bin.exists() {
return Ok(bin);
}
}
Err(TestbedError::Qcow2Error {
message: "mise not found on PATH or ~/.local/bin".to_string(),
})
}