find_lockfile

Function find_lockfile 

Source
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

  1. Start from current working directory
  2. Check for agpm.lock in current directory
  3. If found, return the path
  4. If not found, move to parent directory
  5. Repeat until root directory is reached
  6. Return None if no lockfile found

§Returns

  • Some(PathBuf) - Path to the found lockfile
  • None - 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.