use anyhow::{Context, Result};
use console::style;
use std::process::Command;
pub async fn handle(target: String, open: bool) -> Result<()> {
println!(
"{}",
style(format!("📚 Generating documentation (target: {})", target))
.bold()
.cyan()
);
println!("\n{}", style("🦀 Generating Rust docs...").cyan());
let mut cargo_doc = Command::new("cargo");
cargo_doc.arg("doc");
cargo_doc.arg("--no-deps");
if open && target == "rust" {
cargo_doc.arg("--open");
}
let status = cargo_doc.status().context("Failed to run cargo doc")?;
if !status.success() {
anyhow::bail!("Failed to generate Rust docs");
}
if target == "python" || target == "all" {
println!("\n{}", style("🐍 Generating Python docs...").cyan());
if Command::new("pdoc").arg("--version").output().is_ok() {
println!(" Run `pdoc <package_name>` to view Python docs.");
if open {
println!(" (Skipping auto-open for Python docs)");
}
} else {
println!(
" {} pdoc not found. Install it with `pip install pdoc` for better Python docs.",
style("⚠").yellow()
);
}
}
if target == "nodejs" || target == "all" {
println!(
"\n{}",
style("Node.js docs generation not yet fully supported.").yellow()
);
println!(" (Type definitions .d.ts are generated during build)");
}
println!("\n{}", style("√ Docs generation complete!").green());
Ok(())
}