pub fn find_lockfile() -> Option<PathBuf>Expand description
Find the lockfile in the current or parent directories.
Searches upward from the current working directory to find a agpm.lock file,
similar to how Git searches for .git directories. This enables running AGPM
commands from subdirectories within a project.
§Search Algorithm
- Start from current working directory
- Check for
agpm.lockin current directory - If found, return the path
- If not found, move to parent directory
- Repeat until root directory is reached
- Return
Noneif no lockfile found
§Returns
Some(PathBuf)- Path to the found lockfileNone- No lockfile found in current or parent directories
§Examples
use agpm_cli::lockfile::find_lockfile;
if let Some(lockfile_path) = find_lockfile() {
println!("Found lockfile: {}", lockfile_path.display());
} else {
println!("No lockfile found (run 'agpm install' to create one)");
}§Use Cases
- CLI commands: Find project root when run from subdirectories
- Editor integration: Locate project configuration
- Build scripts: Find lockfile for dependency information
- Validation tools: Check if project has lockfile
§Directory Structure Example
project/
├── agpm.lock # ← This will be found
├── agpm.toml
└── src/
└── subdir/ # ← Commands run from here will find ../agpm.lock§Errors
This function does not return errors but rather None if:
- Cannot get current working directory (permission issues)
- No lockfile exists in the directory tree
- IO errors while checking file existence
For more robust error handling, consider using LockFile::load directly
with a known path.