mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 05:28:42 +00:00
Refactor main.rs
: Extract new fn install
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
40a872dbe3
commit
d514219ee4
1 changed files with 40 additions and 31 deletions
71
src/main.rs
71
src/main.rs
|
@ -2,7 +2,7 @@ use std::{
|
|||
collections::BTreeSet,
|
||||
ffi::OsString,
|
||||
mem::take,
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
process::{ExitCode, Termination},
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
|
@ -317,36 +317,7 @@ async fn entry() -> Result<()> {
|
|||
|
||||
let tasks: Vec<_> = resolutions
|
||||
.into_iter()
|
||||
.map(|resolution| match resolution {
|
||||
Resolution::Fetch {
|
||||
fetcher,
|
||||
package,
|
||||
crate_name,
|
||||
version,
|
||||
bin_path,
|
||||
bin_files,
|
||||
} => tokio::spawn(install_from_package(
|
||||
fetcher,
|
||||
opts.clone(),
|
||||
package,
|
||||
crate_name,
|
||||
temp_dir.path().to_path_buf(),
|
||||
version,
|
||||
bin_path,
|
||||
bin_files,
|
||||
)),
|
||||
Resolution::InstallFromSource { package } => {
|
||||
if !opts.dry_run {
|
||||
tokio::spawn(install_from_source(package, Arc::clone(&target)))
|
||||
} else {
|
||||
info!(
|
||||
"Dry-run: running `cargo install {} --version {} --target {target}`",
|
||||
package.name, package.version
|
||||
);
|
||||
tokio::spawn(async { Ok(()) })
|
||||
}
|
||||
}
|
||||
})
|
||||
.map(|resolution| install(resolution, &opts, temp_dir.path(), &target))
|
||||
.collect();
|
||||
|
||||
for task in tasks {
|
||||
|
@ -528,6 +499,44 @@ fn collect_bin_files(
|
|||
Ok(bin_files)
|
||||
}
|
||||
|
||||
fn install(
|
||||
resolution: Resolution,
|
||||
opts: &Arc<Options>,
|
||||
temp_dir: &Path,
|
||||
target: &Arc<str>,
|
||||
) -> tokio::task::JoinHandle<Result<()>> {
|
||||
match resolution {
|
||||
Resolution::Fetch {
|
||||
fetcher,
|
||||
package,
|
||||
crate_name,
|
||||
version,
|
||||
bin_path,
|
||||
bin_files,
|
||||
} => tokio::spawn(install_from_package(
|
||||
fetcher,
|
||||
opts.clone(),
|
||||
package,
|
||||
crate_name,
|
||||
temp_dir.to_path_buf(),
|
||||
version,
|
||||
bin_path,
|
||||
bin_files,
|
||||
)),
|
||||
Resolution::InstallFromSource { package } => {
|
||||
if !opts.dry_run {
|
||||
tokio::spawn(install_from_source(package, Arc::clone(target)))
|
||||
} else {
|
||||
info!(
|
||||
"Dry-run: running `cargo install {} --version {} --target {target}`",
|
||||
package.name, package.version
|
||||
);
|
||||
tokio::spawn(async { Ok(()) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused, clippy::too_many_arguments)]
|
||||
async fn install_from_package(
|
||||
fetcher: Arc<dyn Fetcher>,
|
||||
|
|
Loading…
Add table
Reference in a new issue