Skip to content

Commit 0cbfb67

Browse files
committed
Let's not accept both, just to be safe
1 parent 8f1f8b8 commit 0cbfb67

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/bin/install.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use cargo::ops;
22
use cargo::core::{SourceId, GitReference};
3-
use cargo::util::{CliResult, Config, ToUrl};
3+
use cargo::util::{CargoError, CliResult, Config, ToUrl};
44

55
#[derive(Deserialize)]
66
pub struct Options {
@@ -153,7 +153,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
153153
};
154154

155155
let krates = options.arg_crate.iter().map(|s| &s[..]).collect::<Vec<_>>();
156-
let vers = options.flag_version.as_ref().or(options.flag_vers.as_ref()).map(|s| &s[..]);
156+
let vers = match (&options.flag_vers, &options.flag_version) {
157+
(&Some(_), &Some(_)) => return Err(CargoError::from("Invalid arguments.").into()),
158+
(&Some(ref v), _) | (_, &Some(ref v)) => Some(v.as_ref()),
159+
_ => None,
160+
};
157161
let root = options.flag_root.as_ref().map(|s| &s[..]);
158162

159163
if options.flag_list {

tests/install.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -933,13 +933,13 @@ fn version_too() {
933933
}
934934

935935
#[test]
936-
fn version_preferred() {
936+
fn not_both_vers_and_version() {
937937
pkg("foo", "0.1.1");
938938
pkg("foo", "0.1.2");
939939

940940
assert_that(cargo_process("install").arg("foo").arg("--version").arg("0.1.1").arg("--vers").arg("0.1.2"),
941-
execs().with_status(0).with_stderr_contains("\
942-
[DOWNLOADING] foo v0.1.1 (registry [..])
941+
execs().with_status(101).with_stderr_contains("\
942+
error: Invalid arguments.
943943
"));
944944
}
945945

0 commit comments

Comments
 (0)