mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 13:38:43 +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,
|
collections::BTreeSet,
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
mem::take,
|
mem::take,
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
process::{ExitCode, Termination},
|
process::{ExitCode, Termination},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
|
@ -317,36 +317,7 @@ async fn entry() -> Result<()> {
|
||||||
|
|
||||||
let tasks: Vec<_> = resolutions
|
let tasks: Vec<_> = resolutions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|resolution| match resolution {
|
.map(|resolution| install(resolution, &opts, temp_dir.path(), &target))
|
||||||
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(()) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for task in tasks {
|
for task in tasks {
|
||||||
|
@ -528,6 +499,44 @@ fn collect_bin_files(
|
||||||
Ok(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)]
|
#[allow(unused, clippy::too_many_arguments)]
|
||||||
async fn install_from_package(
|
async fn install_from_package(
|
||||||
fetcher: Arc<dyn Fetcher>,
|
fetcher: Arc<dyn Fetcher>,
|
||||||
|
|
Loading…
Add table
Reference in a new issue