install_resource_with_progress

Function install_resource_with_progress 

Source
pub async fn install_resource_with_progress(
    entry: &LockedResource,
    resource_dir: &str,
    context: &InstallContext<'_>,
    pb: &ProgressBar,
) -> Result<(bool, String, Option<String>, AppliedPatches, Option<u64>)>
Expand description

Install a single resource with progress bar updates for user feedback.

This function wraps install_resource with progress bar integration to provide real-time feedback during resource installation. It updates the progress bar message before delegating to the core installation logic.

§Arguments

  • entry - The locked resource containing installation metadata
  • project_dir - Root project directory for installation target
  • resource_dir - Subdirectory name for this resource type (e.g., “agents”)
  • cache - Cache instance for Git repository and worktree management
  • force_refresh - Whether to force refresh of cached repositories
  • pb - Progress bar to update with installation status

§Returns

Returns a tuple of:

  • bool: Whether the resource was actually installed (true for new/updated, false for unchanged)
  • String: SHA-256 checksum of the installed file content
  • Option<String>: SHA-256 checksum of the template rendering inputs, or None for non-templated resources
  • AppliedPatches: Information about any patches that were applied during installation

§Progress Integration

The function automatically sets the progress bar message to indicate which resource is currently being installed. This provides users with real-time feedback about installation progress.

§Examples

use agpm_cli::installer::{install_resource_with_progress, InstallContext};
use agpm_cli::lockfile::{LockedResource, LockedResourceBuilder};
use agpm_cli::cache::Cache;
use agpm_cli::core::ResourceType;
use indicatif::ProgressBar;
use std::path::Path;

let cache = Cache::new()?;
let pb = ProgressBar::new(1);
let entry = LockedResourceBuilder::new(
    "example-agent".to_string(),
    "agents/example.md".to_string(),
    "sha256:...".to_string(),
    ".claude/agents/example.md".to_string(),
    ResourceType::Agent,
)
.source(Some("community".to_string()))
.url(Some("https://github.com/example/repo.git".to_string()))
.version(Some("v1.0.0".to_string()))
.resolved_commit(Some("abc123".to_string()))
.tool(Some("claude-code".to_string()))
.build();

let context = InstallContext::builder(Path::new("."), &cache).build();
let (installed, checksum, _old_checksum, _patches, _token_count) = install_resource_with_progress(
    &entry,
    "agents",
    &context,
    &pb
).await?;

pb.inc(1);

§Errors

Returns the same errors as install_resource, including:

  • Repository access failures
  • File system operation errors
  • Invalid markdown content
  • Git worktree creation failures