mirror of
https://github.com/sharkdp/bat.git
synced 2026-10-26 20:16:33 +00:00
42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
use super::*;
|
|
|
|
pub(crate) fn try_syntax_dependencies_to_graphviz_dot_file(
|
|
other_syntax_lookup: &OtherSyntaxLookup,
|
|
syntax_to_dependencies: &SyntaxToDependencies,
|
|
dot_file_path: &str,
|
|
) {
|
|
match syntax_dependencies_to_graphviz_dot_file(
|
|
other_syntax_lookup,
|
|
syntax_to_dependencies,
|
|
dot_file_path,
|
|
) {
|
|
Ok(_) => println!("Wrote graphviz dot file to {}", dot_file_path),
|
|
Err(e) => eprintln!(
|
|
"Failed to write graphviz dot file to {}: {}",
|
|
dot_file_path, e
|
|
),
|
|
};
|
|
}
|
|
|
|
fn syntax_dependencies_to_graphviz_dot_file(
|
|
other_syntax_lookup: &OtherSyntaxLookup,
|
|
syntax_to_dependencies: &SyntaxToDependencies,
|
|
dot_file_path: &str,
|
|
) -> Result<()> {
|
|
use std::io::Write;
|
|
|
|
let mut dot_file = std::fs::File::create(dot_file_path)?;
|
|
|
|
writeln!(dot_file, "digraph BatSyntaxDependencies {{")?;
|
|
for (key, dependencies) in syntax_to_dependencies {
|
|
for dependency in dependencies {
|
|
if let Some(dep) = other_syntax_lookup.get(dependency) {
|
|
writeln!(dot_file, " \"{}\" -> \"{}\"", key, dep.name)?;
|
|
}
|
|
}
|
|
}
|
|
writeln!(dot_file, "}}")?;
|
|
|
|
Ok(())
|
|
}
|