handle_legacy_ccpm_migration

Function handle_legacy_ccpm_migration 

Source
pub async fn handle_legacy_ccpm_migration(
    from_dir: Option<PathBuf>,
    yes: bool,
) -> Result<Option<PathBuf>>
Expand description

Handle legacy CCPM files by offering interactive migration.

This function searches for ccpm.toml and ccpm.lock files in the current directory and parent directories. If found, it prompts the user to migrate and performs the migration if they accept.

§Behavior

  • Interactive mode: Prompts user with Y/n confirmation (stdin is a TTY)
  • Non-interactive mode: Returns Ok(None) if stdin is not a TTY (e.g., CI/CD)
  • Auto-accept mode: When yes is true, accepts migration without prompting
  • Search scope: Traverses from current directory to filesystem root

§Arguments

  • from_dir - Optional starting directory for the search
  • yes - When true, automatically accept migration prompts without user interaction

§Returns

  • Ok(Some(PathBuf)) with the path to agpm.toml if migration succeeded
  • Ok(None) if no legacy files were found OR user declined OR non-interactive mode
  • Err if migration failed

§Examples

use agpm_cli::cli::common::handle_legacy_ccpm_migration;

// Interactive mode
match handle_legacy_ccpm_migration(None, false).await? {
    Some(path) => println!("Migrated to: {}", path.display()),
    None => println!("No migration performed"),
}

// Auto-accept mode (for CI/scripts)
match handle_legacy_ccpm_migration(None, true).await? {
    Some(path) => println!("Migrated to: {}", path.display()),
    None => println!("No legacy files found"),
}

§Errors

Returns an error if:

  • Unable to access current directory (when from_dir is None)
  • Unable to perform migration operations