Actually implement --dry-run

This commit is contained in:
Félix Saparelli 2022-02-16 16:29:18 +13:00 committed by Félix Saparelli
parent 6dcb1dd1b4
commit 5ef8abda3a

View file

@ -157,7 +157,7 @@ async fn main() -> Result<(), anyhow::Error> {
"The package will be downloaded from third-party source {}", "The package will be downloaded from third-party source {}",
fetcher.source_name() fetcher.source_name()
); );
if !opts.no_confirm && !confirm()? { if !opts.no_confirm && !opts.dry_run && !confirm()? {
warn!("Installation cancelled"); warn!("Installation cancelled");
return Ok(()); return Ok(());
} }
@ -169,7 +169,11 @@ async fn main() -> Result<(), anyhow::Error> {
} }
// Download package // 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)] #[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)); 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.dry_run {
if opts.no_cleanup { // Extract files
let _ = temp_dir.into_path(); extract(&pkg_path, fetcher.pkg_fmt(), &bin_path)?;
}
if binaries.len() == 0 { // Bypass cleanup if disabled
error!("No binaries specified (or inferred from file system)"); if opts.no_cleanup {
return Err(anyhow::anyhow!( let _ = temp_dir.into_path();
"No binaries specified (or inferred from file system)" }
));
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 // 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()? { if !opts.no_confirm && !confirm()? {
warn!("Installation cancelled"); warn!("Installation cancelled");
return Ok(()); return Ok(());