apicurio_cli/commands/
pull.rs1use anyhow::Result;
2use std::{collections::HashMap, fs, path::PathBuf};
3
4use crate::{
5 config::{load_global_config, load_repo_config},
6 constants::{APICURIO_CONFIG, APICURIO_LOCK},
7 lockfile::LockFile,
8 registry::RegistryClient,
9};
10
11pub async fn run() -> Result<()> {
12 let repo_cfg = load_repo_config(&PathBuf::from(APICURIO_CONFIG))?;
14 let global_cfg = load_global_config()?;
15 let regs = repo_cfg.merge_registries(global_cfg)?;
16 let mut clients = HashMap::new();
18 for r in ®s {
19 clients.insert(r.name.clone(), RegistryClient::new(r)?);
20 }
21
22 crate::commands::lock::run().await?;
23 let lock_path = PathBuf::from(APICURIO_LOCK);
24 let lock_file = LockFile::load(&lock_path)?;
25 for dependency in lock_file.locked_dependencies {
26 let client = &clients[&dependency.registry];
27 let data = client
29 .client
30 .get(&dependency.download_url)
31 .send()
32 .await?
33 .bytes()
34 .await?;
35 let file_path = PathBuf::from(&dependency.output_path);
36 if let Some(parent) = file_path.parent() {
37 fs::create_dir_all(parent)?;
38 }
39 fs::write(&file_path, &data)?;
40 }
41
42 println!("✅ pull complete");
43 Ok(())
44}