From: Ashe Connor Date: Wed, 18 Oct 2017 06:18:42 +0000 (+1100) Subject: Allow --version as well (preferred) X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~5^2~36^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8f1f8b8ebae61a2fe37ab2e135aa39cc01040014;p=cargo.git Allow --version as well (preferred) --- diff --git a/src/bin/install.rs b/src/bin/install.rs index c7062d40c..27b63e197 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -24,6 +24,7 @@ pub struct Options { arg_crate: Vec, flag_vers: Option, + flag_version: Option, flag_git: Option, flag_branch: Option, @@ -43,7 +44,8 @@ Usage: cargo install [options] --list Specifying what crate to install: - --vers VERS Specify a version to install from crates.io + --vers VERSION Specify a version to install from crates.io + --version VERSION --git URL Git URL to install the specified crate from --branch BRANCH Branch to use when installing from git --tag TAG Tag to use when installing from git @@ -151,7 +153,7 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { }; let krates = options.arg_crate.iter().map(|s| &s[..]).collect::>(); - let vers = options.flag_vers.as_ref().map(|s| &s[..]); + let vers = options.flag_version.as_ref().or(options.flag_vers.as_ref()).map(|s| &s[..]); let root = options.flag_root.as_ref().map(|s| &s[..]); if options.flag_list { diff --git a/tests/install.rs b/tests/install.rs index d472a324b..c98d4e1ae 100644 --- a/tests/install.rs +++ b/tests/install.rs @@ -921,6 +921,28 @@ fn vers_precise() { ")); } +#[test] +fn version_too() { + pkg("foo", "0.1.1"); + pkg("foo", "0.1.2"); + + assert_that(cargo_process("install").arg("foo").arg("--version").arg("0.1.1"), + execs().with_status(0).with_stderr_contains("\ + [DOWNLOADING] foo v0.1.1 (registry [..]) +")); +} + +#[test] +fn version_preferred() { + pkg("foo", "0.1.1"); + pkg("foo", "0.1.2"); + + assert_that(cargo_process("install").arg("foo").arg("--version").arg("0.1.1").arg("--vers").arg("0.1.2"), + execs().with_status(0).with_stderr_contains("\ + [DOWNLOADING] foo v0.1.1 (registry [..]) +")); +} + #[test] fn legacy_version_requirement() { pkg("foo", "0.1.1");