Skip to content

Commit

Permalink
feat(cli): emit error when install is given a toolchain name instead …
Browse files Browse the repository at this point in the history
…of crate name
  • Loading branch information
danilhendrasr committed Jun 3, 2023
1 parent afcd70a commit 5be09b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::command_prelude::*;

use anyhow::anyhow;
use cargo::core::{GitReference, SourceId, Workspace};
use cargo::ops;
use cargo::util::IntoUrl;
Expand Down Expand Up @@ -108,6 +109,16 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
.map(|k| resolve_crate(k, version))
.collect::<crate::CargoResult<Vec<_>>>()?;

for (crate_name, _) in krates.iter() {
if let Some(toolchain) = crate_name.strip_prefix("+") {
return Err(anyhow!(
"invalid character `+` in dependency name: \"+{toolchain}\"
Use `cargo +{toolchain} install` if you meant to use the `{toolchain}` toolchain."
)
.into());
}
}

let mut from_cwd = false;

let source = if let Some(url) = args.get_one::<String>("git") {
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ fn simple() {
assert_has_not_installed_exe(cargo_home(), "foo");
}

#[cargo_test]
fn toolchain() {
pkg("foo", "0.0.1");

cargo_process("install +nightly")
.with_status(101)
.with_stderr(
"\
[ERROR] invalid character `+` in dependency name: \"+nightly\"
Use `cargo +nightly install` if you meant to use the `nightly` toolchain.",
)
.run();
}

#[cargo_test]
fn simple_with_message_format() {
pkg("foo", "0.0.1");
Expand Down

0 comments on commit 5be09b9

Please sign in to comment.