Skip to main content

zoi_cli/cmd/
unpin.rs

1//! Logic for the `unpin` command.
2
3use anyhow::Result;
4use colored::Colorize;
5
6use crate::pkg::{pin, resolve};
7
8/// Run the unpin command.
9///
10/// # Errors
11///
12/// Returns an error if the package cannot be resolved or if updating the pin
13/// configuration fails.
14pub fn run(source: &str) -> Result<()> {
15    let (pkg, _, _, _, _registry_handle, _, _) =
16        resolve::resolve_package_and_version(source, None, false, false)?;
17    let mut pinned_packages = pin::get_pinned_packages()?;
18
19    let initial_len = pinned_packages.len();
20    pinned_packages.retain(|p| p.source != pkg.name);
21
22    if pinned_packages.len() == initial_len {
23        println!("Package '{}' was not pinned.", pkg.name);
24        return Ok(());
25    }
26
27    pin::write_pinned_packages(&pinned_packages)?;
28
29    println!("Unpinned {}", pkg.name.green());
30    Ok(())
31}