aboutsummaryrefslogtreecommitdiff
path: root/src/output/mod.rs
blob: c1cd7879045b9f5f32f66d030bb0c12415485884 (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
use super::{FightOutcome, LogResult, Opt};

use std::io;

pub mod aggregators;
pub mod formats;
pub mod pipeline;
pub mod sorting;

pub use self::pipeline::Pipeline;

use self::{aggregators::Aggregator, formats::Format};

/// Build an pipeline for the given command line options.
pub fn build_pipeline(opt: &Opt) -> Pipeline {
    let stream = io::stdout();
    let aggregator: Box<dyn Aggregator> = if let Some(sorting) = &opt.sorting {
        Box::new(aggregators::SortedOutput::new(sorting.clone()))
    } else {
        Box::new(aggregators::WriteThrough)
    };

    let format: Box<dyn Format> = if opt.file_name_only {
        Box::new(formats::FileOnly)
    } else {
        Box::new(formats::HumanReadable {
            show_guilds: opt.guilds,
        })
    };

    Pipeline::new(Box::new(stream), format, aggregator)
}