Skip to content

Commit

Permalink
Merge pull request #3310 from hi-rustin/rustin-patch-help
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 authored Apr 5, 2023
2 parents 3438037 + 4e6bda3 commit e724717
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ use crate::utils::utils;
use crate::Notification;
use crate::{command, Cfg, ComponentStatus, Toolchain};

const TOOLCHAIN_OVERRIDE_ERROR: &str =
"To override the toolchain using the 'rustup +toolchain' syntax, \
make sure to prefix the toolchain override with a '+'";

fn handle_epipe(res: Result<utils::ExitCode>) -> Result<utils::ExitCode> {
match res {
Err(e) => {
Expand Down Expand Up @@ -110,6 +114,10 @@ pub fn main() -> Result<utils::ExitCode> {
write!(process().stdout().lock(), "{err}")?;
return Ok(utils::ExitCode(1));
}
if err.kind() == ValueValidation && err.to_string().contains(TOOLCHAIN_OVERRIDE_ERROR) {
write!(process().stderr().lock(), "{err}")?;
return Ok(utils::ExitCode(1));
}
Err(err)
}
}?;
Expand Down Expand Up @@ -245,7 +253,9 @@ pub(crate) fn cli() -> Command<'static> {
if s.starts_with('+') {
Ok(s.to_owned())
} else {
Err("Toolchain overrides must begin with '+'".to_owned())
Err(format!(
"\"{s}\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. {TOOLCHAIN_OVERRIDE_ERROR}"
))
}
}),
)
Expand Down
9 changes: 9 additions & 0 deletions tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bin.name = "rustup"
args = ["random"]
status.code = 1
stdout = ""
stderr = """
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 '+'
For more information try --help
"""
4 changes: 0 additions & 4 deletions tests/suite/cli_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,10 +944,6 @@ fn override_by_toolchain_on_the_command_line() {
&["rustup", "+foo", "which", "rustc"],
"toolchain 'foo' is not installed",
);
config.expect_err(
&["rustup", "@stable", "which", "rustc"],
r#"Invalid value "@stable" for '<+toolchain>': Toolchain overrides must begin with '+'"#,
);
config.expect_stderr_ok(
&["rustup", "+stable", "set", "profile", "minimal"],
"profile set to 'minimal'",
Expand Down

0 comments on commit e724717

Please sign in to comment.