Treat 1.2.3 as =1.2.3 to match cargo-install

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-12 18:33:31 +10:00
parent e2207f7b59
commit c87941211c
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
2 changed files with 11 additions and 20 deletions

View file

@ -147,8 +147,7 @@ pub enum BinstallError {
///
/// This may be the case when using the `--version` option.
///
/// Note that using `--version 1.2.3` is interpreted as the requirement `^1.2.3` as per
/// Cargo.toml rules. If you want the exact version 1.2.3, use `--version '=1.2.3'`.
/// Note that using `--version 1.2.3` is interpreted as the requirement `=1.2.3`.
///
/// - Code: `binstall::version::mismatch`
/// - Exit: 82

View file

@ -3,7 +3,6 @@ use std::{
ffi::OsString,
path::{Path, PathBuf},
process::{ExitCode, Termination},
str::FromStr,
time::{Duration, Instant},
};
@ -239,13 +238,22 @@ async fn entry() -> Result<()> {
info!("Installing package: '{}'", opts.crate_name);
let version = match (&opts.crate_name.version, &opts.version) {
let mut version = match (&opts.crate_name.version, &opts.version) {
(Some(version), None) => version.to_string(),
(None, Some(version)) => version.to_string(),
(Some(_), Some(_)) => Err(BinstallError::DuplicateVersionReq)?,
(None, None) => "*".to_string(),
};
if version
.chars()
.next()
.map(|ch| ch.is_ascii_digit())
.unwrap_or(false)
{
version.insert(0, '=');
}
// 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)
@ -256,22 +264,6 @@ async fn entry() -> Result<()> {
let package = manifest.package.unwrap();
let is_plain_version = semver::Version::from_str(&version).is_ok();
if is_plain_version && package.version != version {
warn!("Warning!");
eprintln!(
"{:?}",
miette::Report::new(BinstallError::VersionWarning {
ver: package.version.clone(),
req: version.clone(),
})
);
if !opts.dry_run {
uithread.confirm().await?;
}
}
let (mut meta, binaries) = (
package
.metadata