diff options
| author | diogo464 <[email protected]> | 2021-07-08 17:11:46 -0400 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2021-07-08 17:11:46 -0400 |
| commit | ed0baec0a3f953c99445f6842dadc5566e89cb75 (patch) | |
| tree | 9f988c41db34907283dd126dc57d29b3d0792bd9 /dotup_cli/src/commands/unlink.rs | |
Initial commit
Diffstat (limited to 'dotup_cli/src/commands/unlink.rs')
| -rw-r--r-- | dotup_cli/src/commands/unlink.rs | 38 |
1 files changed, 38 insertions, 0 deletions
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 @@ | |||
| 1 | use clap::Clap; | ||
| 2 | use std::{ | ||
| 3 | fs::{DirEntry, Metadata}, | ||
| 4 | path::{Path, PathBuf}, | ||
| 5 | }; | ||
| 6 | |||
| 7 | use super::prelude::*; | ||
| 8 | |||
| 9 | #[derive(Clap)] | ||
| 10 | pub struct Opts { | ||
| 11 | /// Specifies the install base if the links are also to be uninstalled. | ||
| 12 | #[clap(long)] | ||
| 13 | uninstall: Option<PathBuf>, | ||
| 14 | |||
| 15 | #[clap(required = true, min_values = 1)] | ||
| 16 | paths: Vec<PathBuf>, | ||
| 17 | } | ||
| 18 | |||
| 19 | pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { | ||
| 20 | let mut depot = utils::read_depot(&config.archive_path)?; | ||
| 21 | |||
| 22 | for link_id in utils::collect_link_ids_by_base_paths(&depot, &opts.paths) { | ||
| 23 | let link = depot.get_link(link_id).unwrap(); | ||
| 24 | log::info!( | ||
| 25 | "Unlinking(uninstall = {}) : {}", | ||
| 26 | opts.uninstall.is_some(), | ||
| 27 | link | ||
| 28 | ); | ||
| 29 | if let Some(ref install_base) = opts.uninstall { | ||
| 30 | depot.uninstall_link(link, &install_base)?; | ||
| 31 | } | ||
| 32 | depot.remove_link(link_id); | ||
| 33 | } | ||
| 34 | |||
| 35 | utils::write_depot(&depot)?; | ||
| 36 | |||
| 37 | Ok(()) | ||
| 38 | } | ||
