Skip to content

Commit

Permalink
Let's not accept both, just to be safe
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Oct 18, 2017
1 parent 8f1f8b8 commit 0cbfb67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/bin/install.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"));
}

Expand Down

0 comments on commit 0cbfb67

Please sign in to comment.