mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 13:38:43 +00:00
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:
parent
e2207f7b59
commit
c87941211c
2 changed files with 11 additions and 20 deletions
|
@ -147,8 +147,7 @@ pub enum BinstallError {
|
||||||
///
|
///
|
||||||
/// This may be the case when using the `--version` option.
|
/// 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
|
/// Note that using `--version 1.2.3` is interpreted as the requirement `=1.2.3`.
|
||||||
/// Cargo.toml rules. If you want the exact version 1.2.3, use `--version '=1.2.3'`.
|
|
||||||
///
|
///
|
||||||
/// - Code: `binstall::version::mismatch`
|
/// - Code: `binstall::version::mismatch`
|
||||||
/// - Exit: 82
|
/// - Exit: 82
|
||||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -3,7 +3,6 @@ use std::{
|
||||||
ffi::OsString,
|
ffi::OsString,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{ExitCode, Termination},
|
process::{ExitCode, Termination},
|
||||||
str::FromStr,
|
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -239,13 +238,22 @@ async fn entry() -> Result<()> {
|
||||||
|
|
||||||
info!("Installing package: '{}'", opts.crate_name);
|
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(),
|
(Some(version), None) => version.to_string(),
|
||||||
(None, Some(version)) => version.to_string(),
|
(None, Some(version)) => version.to_string(),
|
||||||
(Some(_), Some(_)) => Err(BinstallError::DuplicateVersionReq)?,
|
(Some(_), Some(_)) => Err(BinstallError::DuplicateVersionReq)?,
|
||||||
(None, None) => "*".to_string(),
|
(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
|
// 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: work out which of these to do based on `opts.name`
|
||||||
// TODO: support git-based fetches (whole repo name rather than just crate 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 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) = (
|
let (mut meta, binaries) = (
|
||||||
package
|
package
|
||||||
.metadata
|
.metadata
|
||||||
|
|
Loading…
Add table
Reference in a new issue