Skip to content

Commit e724717

Browse files
authored
Merge pull request #3310 from hi-rustin/rustin-patch-help
2 parents 3438037 + 4e6bda3 commit e724717

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/cli/rustup_mode.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ use crate::utils::utils;
3030
use crate::Notification;
3131
use crate::{command, Cfg, ComponentStatus, Toolchain};
3232

33+
const TOOLCHAIN_OVERRIDE_ERROR: &str =
34+
"To override the toolchain using the 'rustup +toolchain' syntax, \
35+
make sure to prefix the toolchain override with a '+'";
36+
3337
fn handle_epipe(res: Result<utils::ExitCode>) -> Result<utils::ExitCode> {
3438
match res {
3539
Err(e) => {
@@ -110,6 +114,10 @@ pub fn main() -> Result<utils::ExitCode> {
110114
write!(process().stdout().lock(), "{err}")?;
111115
return Ok(utils::ExitCode(1));
112116
}
117+
if err.kind() == ValueValidation && err.to_string().contains(TOOLCHAIN_OVERRIDE_ERROR) {
118+
write!(process().stderr().lock(), "{err}")?;
119+
return Ok(utils::ExitCode(1));
120+
}
113121
Err(err)
114122
}
115123
}?;
@@ -245,7 +253,9 @@ pub(crate) fn cli() -> Command<'static> {
245253
if s.starts_with('+') {
246254
Ok(s.to_owned())
247255
} else {
248-
Err("Toolchain overrides must begin with '+'".to_owned())
256+
Err(format!(
257+
"\"{s}\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. {TOOLCHAIN_OVERRIDE_ERROR}"
258+
))
249259
}
250260
}),
251261
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bin.name = "rustup"
2+
args = ["random"]
3+
status.code = 1
4+
stdout = ""
5+
stderr = """
6+
error: Invalid value \"random\" for '<+toolchain>': \"random\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. To override the toolchain using the 'rustup +toolchain' syntax, make sure to prefix the toolchain override with a '+'
7+
8+
For more information try --help
9+
"""

tests/suite/cli_misc.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,10 +944,6 @@ fn override_by_toolchain_on_the_command_line() {
944944
&["rustup", "+foo", "which", "rustc"],
945945
"toolchain 'foo' is not installed",
946946
);
947-
config.expect_err(
948-
&["rustup", "@stable", "which", "rustc"],
949-
r#"Invalid value "@stable" for '<+toolchain>': Toolchain overrides must begin with '+'"#,
950-
);
951947
config.expect_stderr_ok(
952948
&["rustup", "+stable", "set", "profile", "minimal"],
953949
"profile set to 'minimal'",

0 commit comments

Comments
 (0)