diff --git a/src/errors.rs b/src/errors.rs index 286a3c9a..855a23b5 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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 diff --git a/src/main.rs b/src/main.rs index 73512c34..b5a8af31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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