summaryrefslogtreecommitdiffstats
path: root/src/project/path.rs
blob: 0e38990662cda293fcef11cc14f07794068cf937 (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 super::{Project, ProjectParser};

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

impl ProjectParser for PathMatcher {
    #[tracing::instrument]
    fn parse(&self, path_buf: PathBuf) -> Result<Project, Box<dyn std::error::Error>> {
        let project = match self {
            PathMatcher::All => path_buf.try_into()?,
            PathMatcher::Pattern(p) if path_buf.join(p).exists() => path_buf.try_into()?,
            _ => return Err(Box::new(std::io::Error::from(ErrorKind::NotFound))),
        };

        Ok(project)
    }
}