add output option in cli arguments

This commit is contained in:
Michael Sippel 2025-05-10 15:40:49 +02:00
parent a58ac1a69c
commit 783c70b2e2
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -17,7 +17,7 @@ use {
clap::Parser, clap::Parser,
walkdir::WalkDir, walkdir::WalkDir,
tiny_ansi::TinyAnsi, tiny_ansi::TinyAnsi,
std::{path::PathBuf, sync::{Arc, RwLock}}, std::{path::PathBuf, sync::{Arc, RwLock}, io::Write},
}; };
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -27,7 +27,10 @@ struct Args {
morphism_base: Vec<PathBuf>, morphism_base: Vec<PathBuf>,
#[arg(short='m', long="morph")] #[arg(short='m', long="morph")]
morphisms: Vec<String> morphisms: Vec<String>,
#[arg(short='o', long)]
output: Option<PathBuf>
} }
fn main() { fn main() {
@ -103,7 +106,11 @@ fn main() {
} }
} }
println!("{}", let c_source = crate::c_gen::gen_lib::generate_lib(&mut type_dict, instances).expect("failed to generate library");
crate::c_gen::gen_lib::generate_lib(&mut type_dict, instances).expect("failed to generate main function") if let Some(out_path) = args.output {
); let mut file = std::fs::File::create(out_path).expect("failed to open output file");
file.write_all(c_source.as_bytes()).expect("failed to write output file");
} else {
println!("{}", c_source);
}
} }