use std::process::{Command, Stdio};
const REQUIRED_BINS: &[&str] = &[
"greentic-cards2pack",
"greentic-bundle",
"greentic-deployer",
];
pub fn ensure_dependencies() {
let missing: Vec<&str> = REQUIRED_BINS
.iter()
.copied()
.filter(|bin| !is_available(bin))
.collect();
if missing.is_empty() {
eprintln!("[flow-builder] All dependencies found.");
return;
}
eprintln!(
"[flow-builder] Missing dependencies: {}",
missing.join(", ")
);
if !is_available("cargo-binstall") {
eprintln!("[flow-builder] cargo-binstall not found — installing via cargo install...");
let ok = Command::new("cargo")
.args(["install", "cargo-binstall"])
.status()
.is_ok_and(|s| s.success());
if !ok {
eprintln!(
"[flow-builder] WARNING: Failed to install cargo-binstall. \
Install dependencies manually:"
);
for bin in &missing {
eprintln!(" cargo install {bin}");
}
return;
}
}
for bin in &missing {
eprintln!("[flow-builder] Installing {bin}...");
let ok = Command::new("cargo")
.args(["binstall", bin, "--no-confirm"])
.status()
.is_ok_and(|s| s.success());
if ok {
eprintln!("[flow-builder] {bin} installed.");
} else {
eprintln!(
"[flow-builder] WARNING: Failed to install {bin}. \
Install manually: cargo install {bin}"
);
}
}
}
fn is_available(bin: &str) -> bool {
Command::new(bin)
.arg("--version")
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.is_ok_and(|s| s.success())
}