1use std::fs;
4use std::path::PathBuf;
5use crate::utils::me_error::MeError;
6
7#[derive(Debug)]
8pub struct MeSummary {
9 pub alias: String,
10 pub path: PathBuf,
11}
12
13pub fn list_us() -> Result<Vec<MeSummary>, MeError> {
14 let home = dirs::home_dir().ok_or_else(|| MeError::Validation("No HOME dir".to_string()))?;
15 let base_path = home.join(".this").join("me");
16
17 let mut list = vec![];
18
19 if let Ok(entries) = fs::read_dir(base_path) {
20 for entry in entries.flatten() {
21 if entry.path().is_dir() {
22 if let Some(alias) = entry.file_name().to_str() {
23 list.push(MeSummary {
24 alias: alias.to_string(),
25 path: entry.path(),
26 });
27 }
28 }
29 }
30 }
31
32 Ok(list)
33}