aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 151b277..6ebfc45 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,6 +26,8 @@ struct Args {
no_color: bool,
#[clap(short = 'F', long)]
no_filter: bool,
+ #[clap(long)]
+ hdr: Vec<String>,
files: Vec<String>,
}
@@ -42,6 +44,18 @@ impl Args {
self.no_filter
}
+ pub fn hdrs(&self) -> Vec<(String, String)> {
+ self.hdr
+ .iter()
+ .map(|x| x.split_once('='))
+ .filter(|x| x.is_some())
+ .map(|x| {
+ let (def, val) = x.unwrap();
+ (String::from(def), String::from(val))
+ })
+ .collect::<Vec<(String, String)>>()
+ }
+
pub fn output(&self) -> BarbOutput {
BarbOutput::new(
!self.body,
@@ -65,32 +79,32 @@ fn main() {
let mut executor = Executor::new(Context::new(env::vars()));
let output = args.output();
- let files: Vec<Result<BarbFile, String>> = args.files_iter()
- .map(read_file_barb)
- .collect();
+ 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());
+ 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()
+ let mut dependencies = maybe_deps
+ .iter()
.map(|x| x.as_ref().unwrap())
.collect::<Vec<&BarbFile>>();
dependencies.sort();
dependencies.dedup();
for dep in dependencies {
- // Always enable filters on dependencies
- match executor.execute(&dep, &output, args.jq_filter(), false) {
+ match executor.execute_dep(&dep, &output) {
Ok(()) => (),
Err(err) => println!("{}", err),
}
@@ -101,8 +115,14 @@ fn main() {
println!("{}", e);
continue;
}
-
- match executor.execute(&bfile.unwrap(), &output, args.jq_filter(), args.no_filter()) {
+
+ match executor.execute(
+ &bfile.unwrap(),
+ &output,
+ args.jq_filter(),
+ args.no_filter(),
+ args.hdrs(),
+ ) {
Ok(()) => (),
Err(err) => println!("{}", err),
}