aboutsummaryrefslogtreecommitdiffstats
path: root/src/path.rs
blob: 1000b043bb024615e84f32fb0e04eb74bd4131c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::{io::ErrorKind, path::PathBuf};

use crate::{parser::Parser, project::Project};

#[derive(Debug, Clone)]
pub enum PathMatcher {
    All,
    Pattern(String),
}

impl Parser for PathMatcher {
    type Error = std::io::Error;

    #[tracing::instrument]
    fn parse(&self, path_buf: PathBuf) -> Result<Project, Self::Error> {
        match self {
            PathMatcher::All => path_buf.try_into(),
            PathMatcher::Pattern(p) if path_buf.join(p).exists() => path_buf.try_into(),
            _ => Err(std::io::Error::from(ErrorKind::NotFound)),
        }
    }
}