mod barbfile; mod executor; mod output; use clap::Parser; use dotenv::dotenv; use executor::{Context, Executor}; use output::BarbOutput; use std::env; use std::slice::Iter; #[derive(Parser, Debug)] #[clap(version)] struct Args { #[clap(short, long)] headers: bool, #[clap(short, long)] all_headers: bool, #[clap(short, long)] body: bool, #[clap(short, long)] raw: bool, #[clap(short, long)] filter: Option, #[clap(short, long)] no_color: bool, files: Vec, } impl Args { pub fn files_iter(&self) -> Iter { self.files.iter() } pub fn jq_filter(&self) -> &Option { &self.filter } pub fn output(&self) -> BarbOutput { BarbOutput::new( !self.body, self.all_headers, self.headers || self.all_headers || !self.body, !self.headers || self.body, self.raw, !self.no_color, ) } } 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()) { Ok(()) => (), Err(err) => println!("{}", err), } } }