aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 2973b278d4866df40af98fbb489fca0f4deea2bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
mod barbfile;
mod executor;
mod output;

use std::slice::Iter;

use executor::{Context, Executor};
use output::BarbOutput;

use clap::Parser;

use std::env;

use dotenv::dotenv;

#[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<String>,
    #[clap(short, long)]
    path: Option<String>,
    #[clap(short, long)]
    no_color: bool,
    files: Vec<String>,
}

impl Args {
    pub fn files_iter(&self) -> Iter<String> {
        self.files.iter()
    }

    pub fn jq_filter(&self) -> &Option<String> {
        &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()) {
        //match run_file(&args, &mut executor, file) {
            Ok(()) => (),
            Err(err) => println!("{}", err),
        }
    }
}