greentic_ext_runtime/
discovery.rs1use std::path::{Path, PathBuf};
2
3#[derive(Debug, Clone)]
4pub struct DiscoveryPaths {
5 pub user: PathBuf,
6 pub project: Option<PathBuf>,
7}
8
9impl DiscoveryPaths {
10 #[must_use]
11 pub fn new(user: PathBuf) -> Self {
12 Self {
13 user,
14 project: None,
15 }
16 }
17
18 #[must_use]
19 pub fn with_project(mut self, project: PathBuf) -> Self {
20 self.project = Some(project);
21 self
22 }
23
24 #[must_use]
25 pub fn all(&self) -> Vec<&PathBuf> {
26 let mut v = vec![&self.user];
27 if let Some(p) = &self.project {
28 v.push(p);
29 }
30 v
31 }
32
33 #[must_use]
39 pub fn home(&self) -> Option<&Path> {
40 self.user.parent()
41 }
42}
43
44pub fn scan_kind_dir(kind_dir: &Path) -> std::io::Result<Vec<PathBuf>> {
48 if !kind_dir.exists() {
49 return Ok(Vec::new());
50 }
51 let mut out = Vec::new();
52 for entry in std::fs::read_dir(kind_dir)? {
53 let entry = entry?;
54 if !entry.file_type()?.is_dir() {
55 continue;
56 }
57 if entry.path().join("describe.json").exists() {
58 out.push(entry.path());
59 }
60 }
61 out.sort();
62 Ok(out)
63}