Skip to content

Commit 59fa417

Browse files
authored
Merge pull request #2716 from hi-rustin/rustin-patch-arg0
report error when rustup is invoked with unsupported arg0
2 parents 30180f5 + 5e58a18 commit 59fa417

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/bin/rustup-init.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use rustup::cli::setup_mode;
2828
use rustup::currentprocess::{process, with, OSProcess};
2929
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
3030
use rustup::utils::utils;
31+
use rustup::TOOLS;
3132

3233
fn main() {
3334
let process = OSProcess::default();
@@ -92,7 +93,13 @@ fn run_rustup_inner() -> Result<utils::ExitCode> {
9293
}
9394
}
9495
}
95-
Some(_) => proxy_mode::main(),
96+
Some(n) => {
97+
if TOOLS.iter().find(|&&name| name == n).is_some() {
98+
proxy_mode::main()
99+
} else {
100+
Err(ErrorKind::UnknownProxyName(n.to_string()).into())
101+
}
102+
}
96103
None => {
97104
// Weird case. No arg0, or it's unparsable.
98105
Err(ErrorKind::NoExeName.into())

src/cli/errors.rs

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use strsim::damerau_levenshtein;
1313

1414
use super::rustup_mode::CompletionCommand;
1515
use crate::dist::temp;
16+
use crate::TOOLS;
1617

1718
error_chain! {
1819
links {
@@ -47,6 +48,14 @@ error_chain! {
4748
NoExeName {
4849
description("couldn't determine self executable name")
4950
}
51+
UnknownProxyName(n: String) {
52+
description("unknown proxy name")
53+
display(
54+
"unknown proxy name: '{}'; valid proxy names are {}",
55+
n,
56+
valid_proxy_names(),
57+
)
58+
}
5059
NotSelfInstalled(p: PathBuf) {
5160
description("rustup is not installed")
5261
display("rustup is not installed at '{}'", p.display())
@@ -74,6 +83,14 @@ error_chain! {
7483
}
7584
}
7685

86+
fn valid_proxy_names() -> String {
87+
TOOLS
88+
.iter()
89+
.map(|s| format!("'{}'", s))
90+
.collect::<Vec<_>>()
91+
.join(", ")
92+
}
93+
7794
fn maybe_suggest_toolchain(bad_name: &str) -> String {
7895
let bad_name = &bad_name.to_ascii_lowercase();
7996
static VALID_CHANNELS: &[&str] = &["stable", "beta", "nightly"];

tests/cli-misc.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,7 @@ fn rustup_failed_path_search() {
325325
expect_err(
326326
config,
327327
broken,
328-
&format!(
329-
"'fake_proxy{}' is not installed for the toolchain 'custom'",
330-
EXE_SUFFIX
331-
),
328+
&format!("unknown proxy name: 'fake_proxy'; valid proxy names are 'rustc', 'rustdoc', 'cargo', 'rust-lldb', 'rust-gdb', 'rls', 'cargo-clippy', 'clippy-driver', 'cargo-miri'",),
332329
);
333330

334331
// Hardlink will be automatically cleaned up by test setup code

0 commit comments

Comments
 (0)