aboutsummaryrefslogtreecommitdiff
path: root/dotup_cli/src/commands/uninstall.rs
blob: fe44bf0f02791b25c0db4a0bc94e7f7e85b9fda8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::path::PathBuf;

use super::prelude::*;

/// Uninstalls links. (Removes symlinks).
///
/// Uninstalling a link for a file that didnt have a link will do nothing.
/// Uninstalling a directory will recursively uninstall all files under it.
/// Symlinks are only deleted if they were pointing to the correct file.
#[derive(Parser)]
pub struct Opts {
    /// The files/directories to uninstall.
    #[clap(min_values = 1, default_value = ".")]
    paths: Vec<PathBuf>,
}

pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> {
    let depot = utils::read_depot(&config.archive_path)?;

    for link in utils::collect_links_by_base_paths(&depot, &opts.paths) {
        log::info!("Uninstalling link : {}", link);
        depot.uninstall_link(link, &config.install_path)?;
    }

    Ok(())
}