pub fn find_project_root(start: &Path) -> Result<PathBuf>Expand description
Finds the AGPM project root by searching for agpm.toml in the directory hierarchy.
This function starts from the given directory and walks up the directory tree
looking for a agpm.toml file, which indicates the root of a AGPM project.
This is similar to how Git finds the repository root by looking for .git.
§Arguments
start- The directory to start searching from (typically current directory)
§Returns
The path to the directory containing agpm.toml, or an error if not found
§Examples
use agpm_cli::utils::fs::find_project_root;
use std::env;
// Find project root from current directory
let current_dir = env::current_dir()?;
let project_root = find_project_root(¤t_dir)?;
println!("Project root: {}", project_root.display());§Behavior
- Starts from the given directory and searches upward
- Returns the first directory containing
agpm.toml - Canonicalizes the starting path to handle symlinks
- Stops at filesystem root if no
agpm.tomlis found
§Error Cases
- No
agpm.tomlfound in the directory hierarchy - Permission denied accessing parent directories
- Invalid or inaccessible starting path
§Use Cases
- CLI commands that need to operate on the current project
- Finding configuration files relative to project root
- Validating that commands are run within a AGPM project