use std::path::Path;
use anyhow::{Context, Result};
use infigraph_core::Infigraph;
use infigraph_languages::bundled_registry;
pub(crate) fn cmd_visualize(root: &Path) -> Result<()> {
let registry = bundled_registry()?;
let mut prism = Infigraph::open(root, registry)?;
prism.init()?;
let store = prism.store().context("graph not initialized")?;
let conn = store.connection()?;
let gq = infigraph_core::graph::GraphQuery::new(&conn);
let output_path = prism.root().join(".infigraph").join("graph.html");
let path = infigraph_core::viz::generate_html(&gq, &output_path)?;
println!("Graph visualization written to: {}", path);
Ok(())
}
pub(crate) fn cmd_visualize_symbol(root: &Path, symbol_id: &str, depth: u32) -> Result<()> {
let registry = bundled_registry()?;
let mut prism = Infigraph::open(root, registry)?;
prism.init()?;
let store = prism.store().context("graph not initialized")?;
let conn = store.connection()?;
let gq = infigraph_core::graph::GraphQuery::new(&conn);
let safe_name: String = symbol_id
.chars()
.map(|c| {
if c.is_alphanumeric() || c == '-' {
c
} else {
'_'
}
})
.collect();
let output_path = prism
.root()
.join(".infigraph")
.join(format!("symbol-{safe_name}.html"));
let path = infigraph_core::viz::generate_symbol_html(&gq, symbol_id, depth, &output_path)?;
println!("Symbol subgraph written to: {}", path);
Ok(())
}
pub(crate) fn cmd_routes(root: &Path) -> Result<()> {
let registry = bundled_registry()?;
let mut prism = Infigraph::open(root, registry)?;
prism.init()?;
let store = prism.store().context("graph not initialized")?;
let conn = store.connection()?;
let gq = infigraph_core::graph::GraphQuery::new(&conn);
let routes = infigraph_core::routes::detect_routes(&gq)?;
println!("{}", infigraph_core::routes::format_routes(&routes));
Ok(())
}