From 8f21c1694743bdd268a20deb245c2a96edf198ec Mon Sep 17 00:00:00 2001 From: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> Date: Sat, 3 Aug 2024 13:07:38 +1000 Subject: [PATCH] Compute cli_overrides in args::parse Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com> --- crates/bin/src/args.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/bin/src/args.rs b/crates/bin/src/args.rs index 78d003f8..769718d0 100644 --- a/crates/bin/src/args.rs +++ b/crates/bin/src/args.rs @@ -13,7 +13,7 @@ use binstalk::{ ops::resolve::{CrateName, VersionReqExt}, registry::Registry, }; -use binstalk_manifests::cargo_toml_binstall::Strategy; +use binstalk_manifests::cargo_toml_binstall::{PkgOverride, Strategy}; use clap::{builder::PossibleValue, error::ErrorKind, CommandFactory, Parser, ValueEnum}; use compact_str::CompactString; use log::LevelFilter; @@ -464,7 +464,7 @@ impl ValueEnum for StrategyWrapped { } } -pub fn parse() -> Args { +pub fn parse() -> (Args, PkgOverride) { // Filter extraneous arg when invoked by cargo // `cargo run -- --help` gives ["target/debug/cargo-binstall", "--help"] // `cargo binstall --help` gives ["/home/ryan/.cargo/bin/cargo-binstall", "binstall", "--help"] @@ -561,6 +561,8 @@ You cannot use --{option} and specify multiple packages at the same time. Do one } } + let has_strategy_override = !opts.overrides.is_empty(); + // Default strategies if empty if opts.strategies.is_empty() { opts.strategies = vec![ @@ -611,7 +613,22 @@ You cannot use --{option} and specify multiple packages at the same time. Do one _ => (), } - opts + ( + opts, + PkgOverride { + pkg_url: opts.pkg_url, + pkg_fmt: opts.pkg_fmt, + bin_dir: opts.bin_dir, + disabled_strategies: (!opts.disable_strategies.is_empty() || has_strategy_ovrrride).then(|| { + args.disable_strategies + .into_iter() + .map(|strategy| strategy.0) + .collect::>() + .into_boxed_slice() + }), + signing: None, + }, + ) } #[cfg(test)]