aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 6dfb7d3..0cd839c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
mod barbfile;
mod executor;
mod output;
+use barbfile::BarbFile;
use clap::Parser;
use dotenv::dotenv;
use executor::{Context, Executor};
@@ -47,14 +48,54 @@ impl Args {
}
}
+fn read_file_barb(file_name: &String) -> Result<BarbFile, String> {
+ BarbFile::from_file(file_name.to_string())
+ .map_err(|_| String::from(format!("Failed to parse file {}", file_name)))
+}
+
fn main() {
let args = Args::parse();
dotenv().ok();
let mut executor = Executor::new(Context::new(env::vars()));
let output = args.output();
- for file in args.files_iter() {
- match executor.execute(file, &output, args.jq_filter()) {
+ let files: Vec<Result<BarbFile, String>> = args.files_iter()
+ .map(read_file_barb)
+ .collect();
+
+ let (maybe_deps, errors): (Vec<Result<BarbFile, String>>, Vec<Result<BarbFile, String>>) = files.iter()
+ .map(|x| match x.as_ref().ok() {
+ Some(bfile) => bfile.dependency(),
+ None => None
+ })
+ .filter(|x| x.is_some())
+ .map(|x| read_file_barb(&String::from(x.unwrap())))
+ .partition(|x| x.is_ok());
+
+ for e in errors {
+ println!("{}", e.err().unwrap());
+ }
+
+ let mut dependencies = maybe_deps.iter()
+ .map(|x| x.as_ref().unwrap())
+ .collect::<Vec<&BarbFile>>();
+ dependencies.sort();
+ dependencies.dedup();
+
+ for dep in dependencies {
+ match executor.execute(&dep, &output, args.jq_filter()) {
+ Ok(()) => (),
+ Err(err) => println!("{}", err),
+ }
+ }
+
+ for bfile in files {
+ if let Err(e) = bfile {
+ println!("{}", e);
+ continue;
+ }
+
+ match executor.execute(&bfile.unwrap(), &output, args.jq_filter()) {
Ok(()) => (),
Err(err) => println!("{}", err),
}