mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
31 lines
718 B
Rust
31 lines
718 B
Rust
use std::{
|
|
env,
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
pub struct FindRootDirectoryError;
|
|
|
|
pub fn find_agb_root_directory() -> Result<PathBuf, FindRootDirectoryError> {
|
|
let current_path = env::current_dir().map_err(|_| FindRootDirectoryError)?;
|
|
|
|
let mut search_path: &Path = ¤t_path;
|
|
|
|
while !search_path.join("justfile").exists() {
|
|
search_path = search_path.parent().ok_or(FindRootDirectoryError)?;
|
|
}
|
|
|
|
Ok(search_path.to_owned())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::find_agb_root_directory;
|
|
|
|
#[test]
|
|
fn find_agb_root_directory_works() {
|
|
let agb_root = find_agb_root_directory().unwrap();
|
|
assert!(agb_root.join("justfile").exists());
|
|
}
|
|
}
|