use std::path::Path;
use anyhow::{Context, Result};
use cargo_metadata::MetadataCommand;
use super::{Edge, EdgeKind, Graph};
pub fn extract(repo_root: &Path) -> Result<Graph> {
let meta = MetadataCommand::new()
.current_dir(repo_root)
.no_deps()
.exec()
.context("cargo_metadata::MetadataCommand::exec")?;
let mut g = Graph::default();
for p in &meta.packages {
g.nodes.push(p.name.to_string());
for d in &p.dependencies {
g.edges.push(Edge {
from: p.name.to_string(),
to: d.name.clone(),
kind: EdgeKind::DependsOn,
});
}
}
Ok(g)
}