summaryrefslogtreecommitdiffstats
path: root/src/path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/path.rs')
-rw-r--r--src/path.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/path.rs b/src/path.rs
new file mode 100644
index 0000000..05a9caa
--- /dev/null
+++ b/src/path.rs
@@ -0,0 +1,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 {
+ #[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)
+ }
+}