Let's not accept both, just to be safe
authorAshe Connor <ashe@kivikakk.ee>
Wed, 18 Oct 2017 06:39:11 +0000 (17:39 +1100)
committerAshe Connor <ashe@kivikakk.ee>
Wed, 18 Oct 2017 06:39:11 +0000 (17:39 +1100)
src/bin/install.rs
tests/install.rs

index 27b63e197667feddbb9d462f24d8b1779374a0b7..2d3a135a4db35642b6f62e5b728db2014f82caf6 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::core::{SourceId, GitReference};
-use cargo::util::{CliResult, Config, ToUrl};
+use cargo::util::{CargoError, CliResult, Config, ToUrl};
 
 #[derive(Deserialize)]
 pub struct Options {
@@ -153,7 +153,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
     };
 
     let krates = options.arg_crate.iter().map(|s| &s[..]).collect::<Vec<_>>();
-    let vers = options.flag_version.as_ref().or(options.flag_vers.as_ref()).map(|s| &s[..]);
+    let vers = match (&options.flag_vers, &options.flag_version) {
+        (&Some(_), &Some(_)) => return Err(CargoError::from("Invalid arguments.").into()),
+        (&Some(ref v), _) | (_, &Some(ref v)) => Some(v.as_ref()),
+        _ => None,
+    };
     let root = options.flag_root.as_ref().map(|s| &s[..]);
 
     if options.flag_list {
index c98d4e1ae7c2b89403d89ef610215f8989b5d657..da9181f424fa5fe5b4f776a240beac8b15bad341 100644 (file)
@@ -933,13 +933,13 @@ fn version_too() {
 }
 
 #[test]
-fn version_preferred() {
+fn not_both_vers_and_version() {
     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 [..])
+                execs().with_status(101).with_stderr_contains("\
+error: Invalid arguments.
 "));
 }