Add field cli_overrides to binstall::Options

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-21 15:00:01 +10:00
parent f09004b5b7
commit aa88dce215
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
3 changed files with 8 additions and 9 deletions

View file

@ -1,5 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use crate::PkgOverride;
mod resolve; mod resolve;
pub use resolve::*; pub use resolve::*;
@ -11,4 +13,5 @@ pub struct Options {
pub dry_run: bool, pub dry_run: bool,
pub version: Option<String>, pub version: Option<String>,
pub manifest_path: Option<PathBuf>, pub manifest_path: Option<PathBuf>,
pub cli_overrides: PkgOverride,
} }

View file

@ -72,12 +72,10 @@ impl Resolution {
} }
} }
#[allow(clippy::too_many_arguments)]
pub async fn resolve( pub async fn resolve(
opts: Arc<Options>, opts: Arc<Options>,
crate_name: CrateName, crate_name: CrateName,
desired_targets: DesiredTargets, desired_targets: DesiredTargets,
cli_overrides: Arc<PkgOverride>,
temp_dir: Arc<Path>, temp_dir: Arc<Path>,
install_path: Arc<Path>, install_path: Arc<Path>,
client: Client, client: Client,
@ -136,7 +134,7 @@ pub async fn resolve(
target_meta.merge(&o); target_meta.merge(&o);
} }
target_meta.merge(&cli_overrides); target_meta.merge(&opts.cli_overrides);
debug!("Found metadata: {target_meta:?}"); debug!("Found metadata: {target_meta:?}");
let fetcher_data = Data { let fetcher_data = Data {
@ -158,7 +156,7 @@ pub async fn resolve(
if let Some(o) = meta.overrides.get(&fetcher_target.to_owned()).cloned() { if let Some(o) = meta.overrides.get(&fetcher_target.to_owned()).cloned() {
meta.merge(&o); meta.merge(&o);
} }
meta.merge(&cli_overrides); meta.merge(&opts.cli_overrides);
// Generate temporary binary path // Generate temporary binary path
let bin_path = temp_dir.join(format!("bin-{}", crate_name.name)); let bin_path = temp_dir.join(format!("bin-{}", crate_name.name));

View file

@ -203,11 +203,11 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
// Load options // Load options
let mut opts = Options::parse_from(args); let mut opts = Options::parse_from(args);
let cli_overrides = Arc::new(PkgOverride { let cli_overrides = PkgOverride {
pkg_url: opts.pkg_url.take(), pkg_url: opts.pkg_url.take(),
pkg_fmt: opts.pkg_fmt.take(), pkg_fmt: opts.pkg_fmt.take(),
bin_dir: opts.bin_dir.take(), bin_dir: opts.bin_dir.take(),
}); };
let crate_names = take(&mut opts.crate_names); let crate_names = take(&mut opts.crate_names);
if crate_names.len() > 1 && opts.manifest_path.is_some() { if crate_names.len() > 1 && opts.manifest_path.is_some() {
return Err(BinstallError::ManifestPathConflictedWithBatchInstallation.into()); return Err(BinstallError::ManifestPathConflictedWithBatchInstallation.into());
@ -265,6 +265,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
dry_run: opts.dry_run, dry_run: opts.dry_run,
version: opts.version.take(), version: opts.version.take(),
manifest_path: opts.manifest_path.take(), manifest_path: opts.manifest_path.take(),
cli_overrides,
}); });
let tasks: Vec<_> = if !opts.dry_run && !opts.no_confirm { let tasks: Vec<_> = if !opts.dry_run && !opts.no_confirm {
@ -276,7 +277,6 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
binstall_opts.clone(), binstall_opts.clone(),
crate_name, crate_name,
desired_targets.clone(), desired_targets.clone(),
cli_overrides.clone(),
temp_dir_path.clone(), temp_dir_path.clone(),
install_path.clone(), install_path.clone(),
client.clone(), client.clone(),
@ -317,7 +317,6 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
let desired_targets = desired_targets.clone(); let desired_targets = desired_targets.clone();
let client = client.clone(); let client = client.clone();
let crates_io_api_client = crates_io_api_client.clone(); let crates_io_api_client = crates_io_api_client.clone();
let cli_overrides = cli_overrides.clone();
let install_path = install_path.clone(); let install_path = install_path.clone();
tokio::spawn(async move { tokio::spawn(async move {
@ -325,7 +324,6 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
opts.clone(), opts.clone(),
crate_name, crate_name,
desired_targets.clone(), desired_targets.clone(),
cli_overrides,
temp_dir_path, temp_dir_path,
install_path, install_path,
client, client,