diff --git a/crates/binstalk-registry/src/git_registry.rs b/crates/binstalk-registry/src/git_registry.rs index 518a48b0..b707b602 100644 --- a/crates/binstalk-registry/src/git_registry.rs +++ b/crates/binstalk-registry/src/git_registry.rs @@ -1,4 +1,4 @@ -use std::{io, path::PathBuf, sync::Arc}; +use std::{fmt::Display, io, path::PathBuf, sync::Arc}; use binstalk_downloader::remote::Client; use binstalk_types::cargo_toml_binstall::Meta; @@ -73,6 +73,10 @@ impl GitRegistry { })) } + pub fn url(&self) -> impl Display + '_ { + &self.0.url + } + /// WARNING: This is a blocking operation. fn find_crate_matched_ver( repo: &Repository, diff --git a/crates/binstalk-registry/src/lib.rs b/crates/binstalk-registry/src/lib.rs index 59c40c7e..09ef989b 100644 --- a/crates/binstalk-registry/src/lib.rs +++ b/crates/binstalk-registry/src/lib.rs @@ -1,6 +1,6 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] -use std::{io, str::FromStr, sync::Arc}; +use std::{fmt, io, str::FromStr, sync::Arc}; use base16::DecodeError as Base16DecodeError; use binstalk_downloader::{ @@ -197,6 +197,15 @@ impl Registry { } } +impl fmt::Display for Registry { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Registry::Git(registry) => fmt::Display::fmt(®istry.url(), f), + Registry::Sparse(registry) => fmt::Display::fmt(®istry.url(), f), + } + } +} + impl FromStr for Registry { type Err = InvalidRegistryError; diff --git a/crates/binstalk-registry/src/sparse_registry.rs b/crates/binstalk-registry/src/sparse_registry.rs index 7dca1b32..48a4f5b2 100644 --- a/crates/binstalk-registry/src/sparse_registry.rs +++ b/crates/binstalk-registry/src/sparse_registry.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use binstalk_downloader::remote::{Client, Error as RemoteError}; use binstalk_types::cargo_toml_binstall::Meta; use cargo_toml_workspace::cargo_toml::Manifest; @@ -28,6 +30,10 @@ impl SparseRegistry { } } + pub fn url(&self) -> impl Display + '_ { + &self.url + } + async fn get_dl_template(&self, client: &Client) -> Result<&str, RegistryError> { self.dl_template .get_or_try_init(|| { diff --git a/crates/binstalk/src/ops/resolve.rs b/crates/binstalk/src/ops/resolve.rs index e0c5883e..5c6379d9 100644 --- a/crates/binstalk/src/ops/resolve.rs +++ b/crates/binstalk/src/ops/resolve.rs @@ -453,7 +453,17 @@ impl PackageInfo { .fetch_crate_matched(client, &name, version_req), ) .await?, - CrateSource::cratesio_registry(), + { + let registry = format!("{}", opts.registry); + if registry == "https://index.crates.io/" { + CrateSource::cratesio_registry() + } else { + CrateSource { + source_type: SourceType::Registry, + url: MaybeOwned::Owned(Url::parse(®istry)?), + } + } + }, ), }; diff --git a/e2e-tests/registries.sh b/e2e-tests/registries.sh index 7eb3f041..7be7ffaf 100644 --- a/e2e-tests/registries.sh +++ b/e2e-tests/registries.sh @@ -43,20 +43,27 @@ EOF # Install binaries using default registry in config "./$1" binstall --force -y cargo-binstall@0.12.0 +grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml" + test_cargo_binstall_install # Install binaries using registry t2 in config "./$1" binstall --force --registry t2 -y cargo-binstall@0.12.0 +grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml" + test_cargo_binstall_install # Install binaries using registry t3 in env CARGO_REGISTRIES_t3_INDEX='sparse+https://index.crates.io/' "./$1" binstall --force --registry t3 -y cargo-binstall@0.12.0 -test_cargo_binstall_install +grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml" +test_cargo_binstall_install # Install binaries using index directly "./$1" binstall --force --index 'sparse+https://index.crates.io/' -y cargo-binstall@0.12.0 +grep -F "cargo-binstall 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" <"$CARGO_HOME/.crates.toml" + test_cargo_binstall_install