Clarify --version usage and add a warning at runtime (#116)

Fixes #113
This commit is contained in:
Félix Saparelli 2022-04-29 09:33:54 +12:00 committed by GitHub
parent 1757dc5344
commit d68b0a209a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View file

@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{path::PathBuf, str::FromStr};
use log::{debug, error, info, warn, LevelFilter};
use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
@ -20,7 +20,8 @@ struct Options {
#[structopt()]
name: String,
/// Filter for package version to install
/// Filter for package version to install, in Cargo.toml format.
/// Use `=1.2.3` to install a specific version.
#[structopt(long, default_value = "*")]
version: String,
@ -104,6 +105,19 @@ async fn main() -> Result<(), anyhow::Error> {
let manifest = load_manifest_path(manifest_path.join("Cargo.toml"))?;
let package = manifest.package.unwrap();
let is_plain_version = semver::Version::from_str(&opts.version).is_ok();
if is_plain_version && package.version != opts.version {
warn!(
"You specified `--version {o}` but the package resolved that to '{p}', use `={o}` if you want an exact match",
o=opts.version, p=package.version
);
if !opts.no_confirm && !opts.dry_run && !confirm()? {
warn!("Installation cancelled");
return Ok(());
}
}
let (mut meta, binaries) = (
package
.metadata