spool/engine/
project_matcher.rs1use crate::config::AppConfig;
2use crate::domain::MatchedProject;
3use std::path::Path;
4
5pub fn match_project(config: &AppConfig, cwd: &Path) -> Option<MatchedProject> {
6 let normalized_cwd = cwd.canonicalize().unwrap_or_else(|_| cwd.to_path_buf());
7 let mut best_match: Option<(&crate::config::ProjectConfig, &std::path::PathBuf)> = None;
8
9 for project in &config.projects {
10 for repo_path in &project.repo_paths {
11 if normalized_cwd.starts_with(repo_path) {
12 match best_match {
13 Some((_, current_repo_path))
14 if current_repo_path.as_os_str().len() >= repo_path.as_os_str().len() => {}
15 _ => best_match = Some((project, repo_path)),
16 }
17 }
18 }
19 }
20
21 best_match.map(|(project, repo_path)| MatchedProject {
22 id: project.id.clone(),
23 name: project.name.clone(),
24 reason: format!("cwd matched repo_path {}", repo_path.display()),
25 })
26}