add output option in cli arguments
This commit is contained in:
parent
a58ac1a69c
commit
783c70b2e2
1 changed files with 12 additions and 5 deletions
17
src/main.rs
17
src/main.rs
|
@ -17,7 +17,7 @@ use {
|
|||
clap::Parser,
|
||||
walkdir::WalkDir,
|
||||
tiny_ansi::TinyAnsi,
|
||||
std::{path::PathBuf, sync::{Arc, RwLock}},
|
||||
std::{path::PathBuf, sync::{Arc, RwLock}, io::Write},
|
||||
};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -27,7 +27,10 @@ struct Args {
|
|||
morphism_base: Vec<PathBuf>,
|
||||
|
||||
#[arg(short='m', long="morph")]
|
||||
morphisms: Vec<String>
|
||||
morphisms: Vec<String>,
|
||||
|
||||
#[arg(short='o', long)]
|
||||
output: Option<PathBuf>
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -103,7 +106,11 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
println!("{}",
|
||||
crate::c_gen::gen_lib::generate_lib(&mut type_dict, instances).expect("failed to generate main function")
|
||||
);
|
||||
let c_source = crate::c_gen::gen_lib::generate_lib(&mut type_dict, instances).expect("failed to generate library");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue