diff --git a/src/bin/rustup-init.rs b/src/bin/rustup-init.rs index 09b125b87c..07820eeb9a 100644 --- a/src/bin/rustup-init.rs +++ b/src/bin/rustup-init.rs @@ -29,6 +29,7 @@ use rustup::cli::setup_mode; use rustup::currentprocess::{process, with, OSProcess}; use rustup::env_var::RUST_RECURSION_COUNT_MAX; use rustup::utils::utils; +use rustup::TOOLS; fn main() { let process = OSProcess::default(); @@ -93,7 +94,13 @@ fn run_rustup_inner() -> Result { } } } - Some(_) => proxy_mode::main(), + Some(n) => { + if TOOLS.iter().find(|&&name| name == n).is_some() { + proxy_mode::main() + } else { + Err(ErrorKind::UnknownProxyName(n.to_string()).into()) + } + } None => { // Weird case. No arg0, or it's unparsable. Err(ErrorKind::NoExeName.into()) diff --git a/src/cli/errors.rs b/src/cli/errors.rs index 7b5a6ba849..c6f413c55b 100644 --- a/src/cli/errors.rs +++ b/src/cli/errors.rs @@ -13,6 +13,7 @@ use strsim::damerau_levenshtein; use super::rustup_mode::CompletionCommand; use crate::dist::temp; +use crate::TOOLS; error_chain! { links { @@ -47,6 +48,14 @@ error_chain! { NoExeName { description("couldn't determine self executable name") } + UnknownProxyName(n: String) { + description("unknown proxy name") + display( + "unknown proxy name: '{}'; valid proxy names are {}", + n, + valid_proxy_names(), + ) + } NotSelfInstalled(p: PathBuf) { description("rustup is not installed") display("rustup is not installed at '{}'", p.display()) @@ -74,6 +83,14 @@ error_chain! { } } +fn valid_proxy_names() -> String { + TOOLS + .iter() + .map(|s| format!("'{}'", s)) + .collect::>() + .join(", ") +} + fn maybe_suggest_toolchain(bad_name: &str) -> String { let bad_name = &bad_name.to_ascii_lowercase(); static VALID_CHANNELS: &[&str] = &["stable", "beta", "nightly"]; diff --git a/tests/cli-misc.rs b/tests/cli-misc.rs index 92b7619d8a..20f1287902 100644 --- a/tests/cli-misc.rs +++ b/tests/cli-misc.rs @@ -325,10 +325,7 @@ fn rustup_failed_path_search() { expect_err( config, broken, - &format!( - "'fake_proxy{}' is not installed for the toolchain 'custom'", - EXE_SUFFIX - ), + &format!("unknown proxy name: 'fake_proxy'; valid proxy names are 'rustc', 'rustdoc', 'cargo', 'rust-lldb', 'rust-gdb', 'rls', 'cargo-clippy', 'clippy-driver', 'cargo-miri'",), ); // Hardlink will be automatically cleaned up by test setup code