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