From 5ef8abda3a5cb262dfe35bfd3240724e20c55bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Wed, 16 Feb 2022 16:29:18 +1300 Subject: [PATCH] Actually implement --dry-run --- src/main.rs | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9aed9e0c..dbc482b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -157,7 +157,7 @@ async fn main() -> Result<(), anyhow::Error> { "The package will be downloaded from third-party source {}", fetcher.source_name() ); - if !opts.no_confirm && !confirm()? { + if !opts.no_confirm && !opts.dry_run && !confirm()? { warn!("Installation cancelled"); return Ok(()); } @@ -169,7 +169,11 @@ async fn main() -> Result<(), anyhow::Error> { } // Download package - fetcher.fetch(&pkg_path).await?; + if opts.dry_run { + info!("Dry run, not downloading package"); + } else { + fetcher.fetch(&pkg_path).await?; + } #[cfg(incomplete)] { @@ -195,20 +199,24 @@ async fn main() -> Result<(), anyhow::Error> { } } - // Extract files let bin_path = temp_dir.path().join(format!("bin-{}", opts.name)); - extract(&pkg_path, fetcher.pkg_fmt(), &bin_path)?; + debug!("Using temporary binary path: {}", bin_path.display()); - // Bypass cleanup if disabled - if opts.no_cleanup { - let _ = temp_dir.into_path(); - } + if !opts.dry_run { + // Extract files + extract(&pkg_path, fetcher.pkg_fmt(), &bin_path)?; - if binaries.len() == 0 { - error!("No binaries specified (or inferred from file system)"); - return Err(anyhow::anyhow!( - "No binaries specified (or inferred from file system)" - )); + // Bypass cleanup if disabled + if opts.no_cleanup { + let _ = temp_dir.into_path(); + } + + if binaries.is_empty() { + error!("No binaries specified (or inferred from file system)"); + return Err(anyhow::anyhow!( + "No binaries specified (or inferred from file system)" + )); + } } // List files to be installed @@ -241,6 +249,11 @@ async fn main() -> Result<(), anyhow::Error> { } } + if opts.dry_run { + info!("Dry run, not proceeding"); + return Ok(()); + } + if !opts.no_confirm && !confirm()? { warn!("Installation cancelled"); return Ok(());