mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-07 11:16:37 +00:00
Use VersionReq
for Options::version_req
and update usage of
`CrateName` in `binstall::install` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
686cae6ae8
commit
065f62a625
4 changed files with 21 additions and 24 deletions
|
@ -19,7 +19,7 @@ pub async fn install(
|
|||
fetcher,
|
||||
package,
|
||||
name,
|
||||
version,
|
||||
version_req,
|
||||
bin_path,
|
||||
bin_files,
|
||||
} => {
|
||||
|
@ -31,7 +31,7 @@ pub async fn install(
|
|||
.map(|option| {
|
||||
option.map(|bins| MetaData {
|
||||
name,
|
||||
version_req: version,
|
||||
version_req,
|
||||
current_version,
|
||||
source: Source::cratesio_registry(),
|
||||
target,
|
||||
|
|
|
@ -4,10 +4,11 @@ use std::{
|
|||
};
|
||||
|
||||
use cargo_toml::{Package, Product};
|
||||
use compact_str::{format_compact, CompactString};
|
||||
use compact_str::{CompactString, ToCompactString};
|
||||
use log::{debug, error, info, warn};
|
||||
use miette::{miette, Result};
|
||||
use reqwest::Client;
|
||||
use semver::VersionReq;
|
||||
|
||||
use super::Options;
|
||||
use crate::{
|
||||
|
@ -21,7 +22,7 @@ pub enum Resolution {
|
|||
fetcher: Arc<dyn Fetcher>,
|
||||
package: Package<Meta>,
|
||||
name: CompactString,
|
||||
version: CompactString,
|
||||
version_req: CompactString,
|
||||
bin_path: PathBuf,
|
||||
bin_files: Vec<bins::BinFile>,
|
||||
},
|
||||
|
@ -83,30 +84,26 @@ pub async fn resolve(
|
|||
) -> Result<Resolution> {
|
||||
info!("Installing package: '{}'", crate_name);
|
||||
|
||||
let mut version: CompactString = match (&crate_name.version, &opts.version) {
|
||||
let version_req: VersionReq = match (&crate_name.version_req, &opts.version_req) {
|
||||
(Some(version), None) => version.clone(),
|
||||
(None, Some(version)) => version.clone(),
|
||||
(Some(_), Some(_)) => Err(BinstallError::SuperfluousVersionOption)?,
|
||||
(None, None) => "*".into(),
|
||||
(None, None) => VersionReq::STAR,
|
||||
};
|
||||
|
||||
// Treat 0.1.2 as =0.1.2
|
||||
if version
|
||||
.chars()
|
||||
.next()
|
||||
.map(|ch| ch.is_ascii_digit())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
version = format_compact!("={version}");
|
||||
}
|
||||
|
||||
// Fetch crate via crates.io, git, or use a local manifest path
|
||||
// TODO: work out which of these to do based on `opts.name`
|
||||
// TODO: support git-based fetches (whole repo name rather than just crate name)
|
||||
let manifest = match opts.manifest_path.clone() {
|
||||
Some(manifest_path) => load_manifest_path(manifest_path)?,
|
||||
None => {
|
||||
fetch_crate_cratesio(&client, &crates_io_api_client, &crate_name.name, &version).await?
|
||||
fetch_crate_cratesio(
|
||||
&client,
|
||||
&crates_io_api_client,
|
||||
&crate_name.name,
|
||||
&version_req,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -175,7 +172,7 @@ pub async fn resolve(
|
|||
fetcher,
|
||||
package,
|
||||
name: crate_name.name,
|
||||
version,
|
||||
version_req: version_req.to_compact_string(),
|
||||
bin_path,
|
||||
bin_files,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue