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 {}",
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
if opts.dry_run {
info!("Dry run, not downloading package");
} else {
fetcher.fetch(&pkg_path).await?;
}
#[cfg(incomplete)]
{
@ -195,8 +199,11 @@ async fn main() -> Result<(), anyhow::Error> {
}
}
// Extract files
let bin_path = temp_dir.path().join(format!("bin-{}", opts.name));
debug!("Using temporary binary path: {}", bin_path.display());
if !opts.dry_run {
// Extract files
extract(&pkg_path, fetcher.pkg_fmt(), &bin_path)?;
// Bypass cleanup if disabled
@ -204,12 +211,13 @@ async fn main() -> Result<(), anyhow::Error> {
let _ = temp_dir.into_path();
}
if binaries.len() == 0 {
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
// based on those found via Cargo.toml
@ -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(());