cu29_rendercfg/
rendercfg.rsmod config;
use clap::Parser;
use config::read_configuration;
pub use cu29_traits::*;
use std::io::Cursor;
use std::io::Write;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use tempfile::Builder;
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(value_parser)]
config: PathBuf,
#[clap(long)]
open: bool,
}
fn main() -> std::io::Result<()> {
let args = Args::parse();
let config = read_configuration(args.config.to_str().unwrap())
.expect("Failed to read configuration file");
let mut content = Vec::<u8>::new();
{
let mut cursor = Cursor::new(&mut content);
config.render(&mut cursor);
}
let mut child = Command::new("dot")
.arg("-Tsvg")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.expect("Failed to start dot process");
{
let stdin = child.stdin.as_mut().expect("Failed to open stdin");
stdin.write_all(&content)?;
}
let output = child.wait_with_output().expect("Failed to read stdout");
if !output.status.success() {
std::process::exit(1);
}
let graph_svg = output.stdout;
if args.open {
let mut temp_file = Builder::new().suffix(".svg").tempfile()?;
temp_file.write_all(graph_svg.as_slice())?;
Command::new("inkscape") .arg(temp_file.path())
.status()
.expect("failed to open SVG file");
} else {
let mut svg_file = std::fs::File::create("output.svg")?;
svg_file.write_all(graph_svg.as_slice())?;
}
Ok(())
}