From 20c8574ab6b9db586ccc88e453cdb84fe44f1004 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 6 Nov 2021 22:36:28 +0100 Subject: add a dry-run mode to install --- src/main.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 5df16a2..bff0fe0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,6 +44,12 @@ fn main() -> Result<()> { .short("t") .long("target-dir") .default_value("."), + ) + .arg( + Arg::with_name("dry-run") + .short("n") + .long("dry-run") + .required(false), ), ) .get_matches(); @@ -68,8 +74,7 @@ fn main() -> Result<()> { if let Some(install) = matches.subcommand_matches("install") { let mods = install.values_of("mod").unwrap().collect::>(); - let target_dir = install.value_of("target").unwrap(); - install_mods(&mut stdout, &snapshot, &world, &mods, Path::new(target_dir))?; + install_mods(&mut stdout, &snapshot, &world, &mods, install)?; } Ok(()) @@ -183,8 +188,11 @@ fn install_mods( snapshot: &Snapshot, world: &World, mods: &[&str], - target_dir: &Path, + matches: &ArgMatches, ) -> Result<()> { + let target_dir = &Path::new(matches.value_of("target").unwrap()); + let dry_run = matches.is_present("dry-run"); + let content_db = ContentDb::new(); let downloader = Downloader::new()?; let mut wanted = mods @@ -266,6 +274,15 @@ fn install_mods( ask_continue(output)?; + if dry_run { + for m in to_install { + let mod_id = m.mod_id()?; + let mod_dir = target_dir.join(&mod_id); + writeln!(output, "Installing {} to {:?}", mod_id, mod_dir)?; + } + return Ok(()); + } + for m in to_install { let mod_id = m.mod_id()?; writeln!(output, "Installing {}", mod_id)?; -- cgit v1.2.3