agb/tools/src/utils.rs

31 lines
718 B
Rust
Raw Normal View History

2024-03-09 23:09:34 +11:00
use std::{
env,
path::{Path, PathBuf},
};
2022-10-02 06:36:42 +11:00
#[derive(Debug)]
pub struct FindRootDirectoryError;
pub fn find_agb_root_directory() -> Result<PathBuf, FindRootDirectoryError> {
2024-03-09 23:09:34 +11:00
let current_path = env::current_dir().map_err(|_| FindRootDirectoryError)?;
2022-10-02 06:36:42 +11:00
2024-03-09 23:09:34 +11:00
let mut search_path: &Path = &current_path;
while !search_path.join("justfile").exists() {
search_path = search_path.parent().ok_or(FindRootDirectoryError)?;
2022-10-02 06:36:42 +11:00
}
2024-03-09 23:09:34 +11:00
Ok(search_path.to_owned())
2022-10-02 06:36:42 +11:00
}
#[cfg(test)]
mod tests {
use super::find_agb_root_directory;
#[test]
fn find_agb_root_directory_works() {
2024-03-09 23:09:34 +11:00
let agb_root = find_agb_root_directory().unwrap();
assert!(agb_root.join("justfile").exists());
2022-10-02 06:36:42 +11:00
}
}