feature: Merge disable strategies (#1868)

* feat: Merge --disable-strategies with ones in cargo manifest

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Update doc

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Update e2e-test-strategies

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix typo in option doc in crates/bin/src/args.rs

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>

---------

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
This commit is contained in:
Jiahao XU 2024-08-08 00:04:00 +10:00 committed by GitHub
parent 90d47f76b1
commit b854f3f52c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 77 additions and 19 deletions

View file

@ -1,7 +1,7 @@
use std::{
env,
ffi::OsString,
fmt,
fmt, mem,
num::{NonZeroU16, NonZeroU64, ParseIntError},
path::PathBuf,
str::FromStr,
@ -155,6 +155,10 @@ pub struct Args {
/// Specify the strategies to be used,
/// binstall will run the strategies specified in order.
///
/// If this option is specified, then cargo-binstall will ignore
/// `disabled-strategies` in `package.metadata` in the cargo manifest
/// of the installed packages.
///
/// Default value is "crate-meta-data,quick-install,compile".
#[clap(
help_heading = "Overrides",
@ -167,6 +171,10 @@ pub struct Args {
/// Disable the strategies specified.
/// If a strategy is specified in `--strategies` and `--disable-strategies`,
/// then it will be removed.
///
/// If `--strategies` is not specified, then the strategies specified in this
/// option will be merged with the disabled-strategies` in `package.metadata`
/// in the cargo manifest of the installed packages.
#[clap(
help_heading = "Overrides",
long,
@ -570,7 +578,7 @@ You cannot use --{option} and specify multiple packages at the same time. Do one
}
}
let has_strategies_override = !opts.strategies.is_empty();
let ignore_disabled_strategies = !opts.strategies.is_empty();
// Default strategies if empty
if opts.strategies.is_empty() {
@ -626,15 +634,14 @@ You cannot use --{option} and specify multiple packages at the same time. Do one
pkg_url: opts.pkg_url.take(),
pkg_fmt: opts.pkg_fmt.take(),
bin_dir: opts.bin_dir.take(),
disabled_strategies: (!opts.disable_strategies.is_empty() || has_strategies_override).then(
|| {
opts.disable_strategies
.iter()
.map(|strategy| strategy.0)
.collect::<Vec<_>>()
.into_boxed_slice()
},
disabled_strategies: Some(
mem::take(&mut opts.disable_strategies)
.into_iter()
.map(|strategy| strategy.0)
.collect::<Vec<_>>()
.into_boxed_slice(),
),
ignore_disabled_strategies,
signing: None,
};