pakker/crates/pakker-cli/src/cli/commands/fetch.rs
NotAShelf d445b1814a
treewide: migrate to multi-crate layout
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I11a2103f3530f07409177404577b90136a6a6964
2026-05-03 03:44:54 +03:00

51 lines
1.5 KiB
Rust

use std::path::{Path, PathBuf};
use crate::{
cli::FetchArgs,
error::Result,
fetch::Fetcher,
ipc::{IpcCoordinator, OperationGuard, OperationType},
model::{Config, LockFile},
};
pub async fn execute(
args: FetchArgs,
lockfile_path: &Path,
config_path: &Path,
) -> Result<()> {
// Load expects directory path, so get parent directory
let lockfile_dir = lockfile_path.parent().unwrap_or_else(|| Path::new("."));
let config_dir = config_path.parent().unwrap_or_else(|| Path::new("."));
let lockfile = LockFile::load(lockfile_dir)?;
let config = Config::load(config_dir)?;
// Create IPC coordinator for this modpack
let working_dir = PathBuf::from(".");
let coordinator = IpcCoordinator::new(&working_dir)?;
// Check for conflicting operations
if coordinator.has_running_operation(OperationType::Fetch) {
// Wait for conflicting operations to complete with timeout
let timeout = std::time::Duration::from_secs(args.timeout.unwrap_or(300));
coordinator
.wait_for_conflicts(OperationType::Fetch, timeout)
.await?;
}
// Register this fetch operation
let operation_id = coordinator.register_operation(OperationType::Fetch)?;
let _guard = OperationGuard::new(coordinator, operation_id);
// Create fetcher with shelve option
let fetcher = Fetcher::new(".")
.with_shelve(args.shelve)
.with_retry(args.retry);
// Fetch all projects (progress indicators handled in fetch.rs)
fetcher.fetch_all(&lockfile, &config).await?;
println!("Fetch complete");
Ok(())
}