Skip to content

Commit

Permalink
Error if all is combined with other targets
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed May 24, 2019
1 parent bea09a3 commit 10bb000
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ error_chain! {
description("completion script for shell not yet supported for tool")
display("{} does not currently support completions for {}", cmd, shell)
}
TargetAllSpecifiedWithTargets(t: Vec<String>) {
description(
"the `all` target, which installs all available targets, \
cannot be combined with other targets"
)
display("`rustup target add {}` includes `all`", t.join(" "))
}
}
}
4 changes: 4 additions & 0 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ fn target_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
.collect();

if targets.contains(&"all".to_string()) {
if targets.len() != 1 {
return Err(ErrorKind::TargetAllSpecifiedWithTargets(targets).into());
}

targets.clear();
for component in toolchain.list_components()? {
if component.component.short_name_in_manifest() == "rust-std"
Expand Down
23 changes: 23 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,29 @@ fn add_all_targets() {
});
}

#[test]
fn add_all_targets_fail() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_err(
config,
&[
"rustup",
"target",
"add",
clitools::CROSS_ARCH1,
"all",
clitools::CROSS_ARCH2,
],
format!(
"`rustup target add {} all {}` includes `all`",
clitools::CROSS_ARCH1,
clitools::CROSS_ARCH2
),
);
});
}

#[test]
fn add_target_no_toolchain() {
setup(&|config| {
Expand Down

0 comments on commit 10bb000

Please sign in to comment.