From ed0baec0a3f953c99445f6842dadc5566e89cb75 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Thu, 8 Jul 2021 17:11:46 -0400 Subject: Initial commit --- dotup_cli/src/commands/unlink.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 dotup_cli/src/commands/unlink.rs (limited to 'dotup_cli/src/commands/unlink.rs') diff --git a/dotup_cli/src/commands/unlink.rs b/dotup_cli/src/commands/unlink.rs new file mode 100644 index 0000000..7ebb19c --- /dev/null +++ b/dotup_cli/src/commands/unlink.rs @@ -0,0 +1,38 @@ +use clap::Clap; +use std::{ + fs::{DirEntry, Metadata}, + path::{Path, PathBuf}, +}; + +use super::prelude::*; + +#[derive(Clap)] +pub struct Opts { + /// Specifies the install base if the links are also to be uninstalled. + #[clap(long)] + uninstall: Option, + + #[clap(required = true, min_values = 1)] + paths: Vec, +} + +pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { + let mut depot = utils::read_depot(&config.archive_path)?; + + for link_id in utils::collect_link_ids_by_base_paths(&depot, &opts.paths) { + let link = depot.get_link(link_id).unwrap(); + log::info!( + "Unlinking(uninstall = {}) : {}", + opts.uninstall.is_some(), + link + ); + if let Some(ref install_base) = opts.uninstall { + depot.uninstall_link(link, &install_base)?; + } + depot.remove_link(link_id); + } + + utils::write_depot(&depot)?; + + Ok(()) +} -- cgit