From 6817631ddee3795af3a558bf38e477da4ae5b1cb Mon Sep 17 00:00:00 2001 From: diogo464 Date: Fri, 24 Dec 2021 21:09:44 +0000 Subject: made install-path a global option --- dotup_cli/src/commands/install.rs | 11 +---------- dotup_cli/src/commands/status.rs | 8 +++----- dotup_cli/src/commands/uninstall.rs | 11 +---------- dotup_cli/src/config.rs | 1 + dotup_cli/src/main.rs | 14 +++++++++++++- dotup_cli/tests/cli.rs | 6 +++--- 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/dotup_cli/src/commands/install.rs b/dotup_cli/src/commands/install.rs index e166a7b..6d9fbf7 100644 --- a/dotup_cli/src/commands/install.rs +++ b/dotup_cli/src/commands/install.rs @@ -8,26 +8,17 @@ use super::prelude::*; /// If a file or directory already exists at the location a link would be installed this command will fail. #[derive(Parser)] pub struct Opts { - /// The location where links will be installed to. - /// Defaults to the home directory. - #[clap(long)] - install_base: Option, - /// The files/directories to install. #[clap(min_values = 1, default_value = ".")] paths: Vec, } pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { - let install_base = match opts.install_base { - Some(path) => path, - None => utils::home_directory()?, - }; let depot = utils::read_depot(&config.archive_path)?; for link in utils::collect_links_by_base_paths(&depot, &opts.paths) { log::info!("Installing link {}", link); - depot.install_link(link, &install_base)?; + depot.install_link(link, &config.install_path)?; } Ok(()) diff --git a/dotup_cli/src/commands/status.rs b/dotup_cli/src/commands/status.rs index e05ada9..b7221db 100644 --- a/dotup_cli/src/commands/status.rs +++ b/dotup_cli/src/commands/status.rs @@ -25,7 +25,7 @@ pub struct Opts { #[derive(Debug)] struct State { max_depth: u32, - install_base: PathBuf, + install_path: PathBuf, } pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { @@ -67,9 +67,7 @@ pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { let state = State { max_depth: u32::MAX, - install_base: opts - .install_base - .unwrap_or(utils::home_directory().unwrap()), + install_path: config.install_path, }; let (directories, files) = utils::collect_read_dir_split(".")?; @@ -142,7 +140,7 @@ fn print_link(depot: &Depot, state: &State, link: &Link, depth: u32) { }; print_identation(depth); - if depot.is_link_installed(link, &state.install_base) { + if depot.is_link_installed(link, &state.install_path) { println!( "{} -> {}", Colour::Green.paint(&format!("{}", filename.to_string_lossy())), diff --git a/dotup_cli/src/commands/uninstall.rs b/dotup_cli/src/commands/uninstall.rs index fdb1a0a..fe44bf0 100644 --- a/dotup_cli/src/commands/uninstall.rs +++ b/dotup_cli/src/commands/uninstall.rs @@ -9,26 +9,17 @@ use super::prelude::*; /// Symlinks are only deleted if they were pointing to the correct file. #[derive(Parser)] pub struct Opts { - /// The location where links will be uninstalled from. - /// Defaults to home directory. - #[clap(long)] - install_base: Option, - /// The files/directories to uninstall. #[clap(min_values = 1, default_value = ".")] paths: Vec, } pub fn main(config: Config, opts: Opts) -> anyhow::Result<()> { - let install_base = match opts.install_base { - Some(path) => path, - None => utils::home_directory()?, - }; 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, &install_base)?; + depot.uninstall_link(link, &config.install_path)?; } Ok(()) diff --git a/dotup_cli/src/config.rs b/dotup_cli/src/config.rs index ac4fc66..2046ad5 100644 --- a/dotup_cli/src/config.rs +++ b/dotup_cli/src/config.rs @@ -3,4 +3,5 @@ use std::path::PathBuf; #[derive(Debug)] pub struct Config { pub archive_path: PathBuf, + pub install_path: PathBuf, } diff --git a/dotup_cli/src/main.rs b/dotup_cli/src/main.rs index 05fa850..6161ca7 100644 --- a/dotup_cli/src/main.rs +++ b/dotup_cli/src/main.rs @@ -45,6 +45,11 @@ struct Opts { #[clap(short, long, parse(from_occurrences))] verbose: i32, + /// The location where links will be installed to. + /// Defaults to the home directory. + #[clap(short, long)] + install_path: Option, + #[clap(subcommand)] subcmd: SubCommand, } @@ -80,9 +85,16 @@ fn main() -> anyhow::Result<()> { Some(path) => path, None => utils::find_archive_path()?, }; + let install_path = match opts.install_path { + Some(path) => path, + None => utils::home_directory()?, + }; log::debug!("Archive path : {}", archive_path.display()); - let config = Config { archive_path }; + let config = Config { + archive_path, + install_path, + }; match opts.subcmd { SubCommand::Init(opts) => commands::init::main(config, opts), diff --git a/dotup_cli/tests/cli.rs b/dotup_cli/tests/cli.rs index 3b8d657..c836f63 100644 --- a/dotup_cli/tests/cli.rs +++ b/dotup_cli/tests/cli.rs @@ -89,7 +89,7 @@ fn test_cli_install_uninstall_unlink() { let install_base = format!("{}", install_dir.path().display()); run_command( &dir, - &format!("install --install-base {} o1 o2", install_base), + &format!("--install-path {} install o1 o2", install_base), ) .success(); @@ -108,7 +108,7 @@ fn test_cli_install_uninstall_unlink() { run_command( &dir, - &format!("uninstall --install-base {} o1/file.txt", install_base), + &format!("--install-path {} uninstall o1/file.txt", install_base), ) .success(); assert!(!install_dir.path().join(".config/file.txt").exists()); @@ -117,7 +117,7 @@ fn test_cli_install_uninstall_unlink() { run_command( &dir, - &format!("uninstall --install-base {} o1", install_base), + &format!("--install-path {} uninstall o1", install_base), ) .success(); assert!(!install_dir.path().join(".config/file.txt").exists()); -- cgit