Refactor main.rs: Simplify install_from_source

Rm arg `opts`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-18 16:21:03 +10:00
parent d6db552db1
commit 730f7d6c15
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -320,9 +320,16 @@ async fn entry() -> Result<()> {
warn!("The package will be installed from source (with cargo)",); warn!("The package will be installed from source (with cargo)",);
if !opts.dry_run { if !opts.dry_run {
uithread.confirm().await?; uithread.confirm().await?;
}
install_from_source(opts, package, target).await install_from_source(package, target).await
} else {
info!(
"Dry-run: running `cargo install {} --version {} --target {target}`",
package.name, package.version
);
Ok(())
}
} }
} }
} }
@ -595,18 +602,7 @@ async fn install_from_package(
}) })
} }
async fn install_from_source( async fn install_from_source(package: Package<Meta>, target: &str) -> Result<()> {
opts: Arc<Options>,
package: Package<Meta>,
target: &str,
) -> Result<()> {
if opts.dry_run {
info!(
"Dry-run: running `cargo install {} --version {} --target {target}`",
package.name, package.version
);
Ok(())
} else {
debug!( debug!(
"Running `cargo install {} --version {} --target {target}`", "Running `cargo install {} --version {} --target {target}`",
package.name, package.version package.name, package.version
@ -636,4 +632,3 @@ async fn install_from_source(
Err(miette!("Cargo install error")) Err(miette!("Cargo install error"))
} }
} }
}