Skip to main content

flow_core/
project.rs

1use std::path::PathBuf;
2
3#[derive(Debug, Clone)]
4pub struct Project {
5    pub name: String,
6    pub path: PathBuf,
7}
8
9/// Discover all projects in the configured projects directory.
10///
11/// # Errors
12///
13/// Returns an error if the config cannot be loaded or the directory cannot be read.
14pub fn discover_all() -> Result<Vec<Project>, crate::FlowError> {
15    let config = crate::Config::load()?;
16    let mut projects = Vec::new();
17
18    if config.projects_dir.exists() {
19        for entry in std::fs::read_dir(&config.projects_dir)? {
20            let entry = entry?;
21            let path = entry.path();
22            if path.is_dir() && path.join(".git").exists() {
23                let name = path
24                    .file_name()
25                    .and_then(|n| n.to_str())
26                    .unwrap_or("unknown")
27                    .to_string();
28                projects.push(Project { name, path });
29            }
30        }
31    }
32
33    Ok(projects)
34}