mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 22:30:03 +00:00
Feature: Impl opt-out options (#510)
Fixed #136 * Impl opt-out optioins in binstalk * Replace field `Options::{gh_crate, quickinstall}_fetcher` with `resolver` which can determine order of resolver used. * Add new field `Args::{disable_}strategies` * Add new variant `BinstallError::InvalidStrategies` * Add variant `BinstallError::NoFallbackToCargoInstall` * Add code for supporting strategies in mod entry * Test `--disable-strategies` in `tests.sh` * Test for `--strategies` in `tests.sh` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
89fa5b1769
commit
9e80cf0700
6 changed files with 141 additions and 11 deletions
|
@ -310,6 +310,22 @@ pub enum BinstallError {
|
|||
#[diagnostic(severity(error), code(binstall::SourceFilePath))]
|
||||
EmptySourceFilePath,
|
||||
|
||||
/// Invalid strategies configured.
|
||||
///
|
||||
/// - Code: `binstall::strategies`
|
||||
/// - Exit: 93
|
||||
#[error("Invalid strategies configured: {0}")]
|
||||
#[diagnostic(severity(error), code(binstall::strategies))]
|
||||
InvalidStrategies(&'static &'static str),
|
||||
|
||||
/// Fallback to `cargo-install` is disabled.
|
||||
///
|
||||
/// - Code: `binstall::no_fallback_to_cargo_install`
|
||||
/// - Exit: 94
|
||||
#[error("Fallback to cargo-install is disabled")]
|
||||
#[diagnostic(severity(error), code(binstall::no_fallback_to_cargo_install))]
|
||||
NoFallbackToCargoInstall,
|
||||
|
||||
/// A wrapped error providing the context of which crate the error is about.
|
||||
#[error("for crate {crate_name}")]
|
||||
CrateContext {
|
||||
|
@ -348,6 +364,8 @@ impl BinstallError {
|
|||
DuplicateSourceFilePath { .. } => 90,
|
||||
InvalidSourceFilePath { .. } => 91,
|
||||
EmptySourceFilePath => 92,
|
||||
InvalidStrategies(..) => 93,
|
||||
NoFallbackToCargoInstall => 94,
|
||||
CrateContext { error, .. } => error.exit_number(),
|
||||
};
|
||||
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
//! Concrete Binstall operations.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use semver::VersionReq;
|
||||
|
||||
use crate::{manifests::cargo_toml_binstall::PkgOverride, DesiredTargets};
|
||||
use crate::{
|
||||
fetchers::{Data, Fetcher},
|
||||
helpers::remote::Client,
|
||||
manifests::cargo_toml_binstall::PkgOverride,
|
||||
DesiredTargets,
|
||||
};
|
||||
|
||||
pub mod install;
|
||||
pub mod resolve;
|
||||
|
||||
pub type Resolver = fn(&Client, &Arc<Data>) -> Arc<dyn Fetcher>;
|
||||
|
||||
pub struct Options {
|
||||
pub no_symlinks: bool,
|
||||
pub dry_run: bool,
|
||||
|
@ -18,4 +25,5 @@ pub struct Options {
|
|||
pub cli_overrides: PkgOverride,
|
||||
pub desired_targets: DesiredTargets,
|
||||
pub quiet: bool,
|
||||
pub resolver: Vec<Resolver>,
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::{
|
|||
bins,
|
||||
drivers::fetch_crate_cratesio,
|
||||
errors::BinstallError,
|
||||
fetchers::{Data, Fetcher, GhCrateMeta, QuickInstall},
|
||||
fetchers::{Data, Fetcher},
|
||||
helpers::{remote::Client, tasks::AutoAbortJoinHandle},
|
||||
manifests::cargo_toml_binstall::{Meta, PkgMeta},
|
||||
};
|
||||
|
@ -211,7 +211,7 @@ async fn resolve_inner(
|
|||
meta: target_meta,
|
||||
})
|
||||
})
|
||||
.cartesian_product([GhCrateMeta::new, QuickInstall::new])
|
||||
.cartesian_product(&opts.resolver)
|
||||
.map(|(fetcher_data, f)| {
|
||||
let fetcher = f(&client, &fetcher_data);
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue