Allow --version as well (preferred)
authorAshe Connor <ashe@kivikakk.ee>
Wed, 18 Oct 2017 06:18:42 +0000 (17:18 +1100)
committerAshe Connor <ashe@kivikakk.ee>
Wed, 18 Oct 2017 06:18:42 +0000 (17:18 +1100)
src/bin/install.rs
tests/install.rs

index c7062d40c6fd39a08ec6e62078dc664d5caa7e82..27b63e197667feddbb9d462f24d8b1779374a0b7 100644 (file)
@@ -24,6 +24,7 @@ pub struct Options {
 
     arg_crate: Vec<String>,
     flag_vers: Option<String>,
+    flag_version: Option<String>,
 
     flag_git: Option<String>,
     flag_branch: Option<String>,
@@ -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::<Vec<_>>();
-    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 {
index d472a324bfd0e4565d698414f2a0f19259fea963..c98d4e1ae7c2b89403d89ef610215f8989b5d657 100644 (file)
@@ -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");