mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Refactor main.rs
: Simplify install_from_source
Rm arg `opts` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
d6db552db1
commit
730f7d6c15
1 changed files with 35 additions and 40 deletions
75
src/main.rs
75
src/main.rs
|
@ -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,45 +602,33 @@ async fn install_from_package(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn install_from_source(
|
async fn install_from_source(package: Package<Meta>, target: &str) -> Result<()> {
|
||||||
opts: Arc<Options>,
|
debug!(
|
||||||
package: Package<Meta>,
|
"Running `cargo install {} --version {} --target {target}`",
|
||||||
target: &str,
|
package.name, package.version
|
||||||
) -> Result<()> {
|
);
|
||||||
if opts.dry_run {
|
let mut child = Command::new("cargo")
|
||||||
info!(
|
.arg("install")
|
||||||
"Dry-run: running `cargo install {} --version {} --target {target}`",
|
.arg(package.name)
|
||||||
package.name, package.version
|
.arg("--version")
|
||||||
);
|
.arg(package.version)
|
||||||
|
.arg("--target")
|
||||||
|
.arg(target)
|
||||||
|
.spawn()
|
||||||
|
.into_diagnostic()
|
||||||
|
.wrap_err("Spawning cargo install failed.")?;
|
||||||
|
debug!("Spawned command pid={:?}", child.id());
|
||||||
|
|
||||||
|
let status = child
|
||||||
|
.wait()
|
||||||
|
.await
|
||||||
|
.into_diagnostic()
|
||||||
|
.wrap_err("Running cargo install failed.")?;
|
||||||
|
if status.success() {
|
||||||
|
info!("Cargo finished successfully");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
debug!(
|
error!("Cargo errored! {status:?}");
|
||||||
"Running `cargo install {} --version {} --target {target}`",
|
Err(miette!("Cargo install error"))
|
||||||
package.name, package.version
|
|
||||||
);
|
|
||||||
let mut child = Command::new("cargo")
|
|
||||||
.arg("install")
|
|
||||||
.arg(package.name)
|
|
||||||
.arg("--version")
|
|
||||||
.arg(package.version)
|
|
||||||
.arg("--target")
|
|
||||||
.arg(target)
|
|
||||||
.spawn()
|
|
||||||
.into_diagnostic()
|
|
||||||
.wrap_err("Spawning cargo install failed.")?;
|
|
||||||
debug!("Spawned command pid={:?}", child.id());
|
|
||||||
|
|
||||||
let status = child
|
|
||||||
.wait()
|
|
||||||
.await
|
|
||||||
.into_diagnostic()
|
|
||||||
.wrap_err("Running cargo install failed.")?;
|
|
||||||
if status.success() {
|
|
||||||
info!("Cargo finished successfully");
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
error!("Cargo errored! {status:?}");
|
|
||||||
Err(miette!("Cargo install error"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue