summaryrefslogtreecommitdiffstats
path: root/src/stdio.rs
blob: 84319a16ef7934b2ab92c356b8ae619d99bb8f45 (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
use std::convert::Infallible;

use clap::Args;

use crate::{session::SessionWriter, Session};

#[derive(Debug, Clone, Args)]
#[group(skip)]
pub struct Config {
    /// Exclude item from output
    #[arg(short, long)]
    pub exclude: Vec<String>,
}

impl Config {
    pub fn new(Config { exclude }: Config) -> Self {
        Self { exclude }
    }
}

pub struct Stdout {
    exclude: Vec<String>,
}

impl Stdout {
    pub fn new(Config { exclude }: Config) -> Self {
        Self { exclude }
    }
}

impl SessionWriter for Stdout {
    type Writer = std::io::Stdout;
    type Error = Infallible;

    fn format(&self, session: &Session) -> Result<String, Self::Error> {
        Ok(session.name.to_string())
    }

    fn filter(&self, session: &Session) -> bool {
        !self.exclude.contains(&session.name)
    }

    fn writer(&self) -> Result<Self::Writer, std::io::Error> {
        Ok(std::io::stdout())
    }
}