Skip to content

Commit a6a8587

Browse files
committed
Better error instead of show the help
Signed-off-by: hi-rustin <[email protected]>
1 parent b579e23 commit a6a8587

File tree

3 files changed

+12
-54
lines changed

3 files changed

+12
-54
lines changed

src/cli/rustup_mode.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,8 @@ pub fn main() -> Result<utils::ExitCode> {
114114
write!(process().stdout().lock(), "{err}")?;
115115
return Ok(utils::ExitCode(1));
116116
}
117-
if err.kind() == ValueValidation {
118-
if err.to_string().contains(TOOLCHAIN_OVERRIDE_ERROR) {
119-
err!("{TOOLCHAIN_OVERRIDE_ERROR}\n");
120-
cli().print_help()?;
121-
} else {
122-
write!(process().stdout().lock(), "{err}")?;
123-
}
117+
if err.kind() == ValueValidation && err.to_string().contains(TOOLCHAIN_OVERRIDE_ERROR) {
118+
write!(process().stderr().lock(), "{err}")?;
124119
return Ok(utils::ExitCode(1));
125120
}
126121
Err(err)
@@ -258,7 +253,9 @@ pub(crate) fn cli() -> Command<'static> {
258253
if s.starts_with('+') {
259254
Ok(s.to_owned())
260255
} else {
261-
Err(TOOLCHAIN_OVERRIDE_ERROR.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+
))
262259
}
263260
}),
264261
)
Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,9 @@
11
bin.name = "rustup"
22
args = ["random"]
33
status.code = 1
4-
stdout = """
5-
rustup [..]
6-
The Rust toolchain installer
7-
8-
USAGE:
9-
rustup[EXE] [OPTIONS] [+toolchain] <SUBCOMMAND>
10-
11-
ARGS:
12-
<+toolchain> release channel (e.g. +stable) or custom toolchain to set override
13-
14-
OPTIONS:
15-
-v, --verbose Enable verbose output
16-
-q, --quiet Disable progress output
17-
-h, --help Print help information
18-
-V, --version Print version information
19-
20-
SUBCOMMANDS:
21-
show Show the active and installed toolchains or profiles
22-
update Update Rust toolchains and rustup
23-
check Check for updates to Rust toolchains and rustup
24-
default Set the default toolchain
25-
toolchain Modify or query the installed toolchains
26-
target Modify a toolchain's supported targets
27-
component Modify a toolchain's installed components
28-
override Modify directory toolchain overrides
29-
run Run a command with an environment configured for a given toolchain
30-
which Display which binary will be run for a given command
31-
doc Open the documentation for the current toolchain
32-
...
33-
self Modify the rustup installation
34-
set Alter rustup settings
35-
completions Generate tab-completion scripts for your shell
36-
help Print this message or the help of the given subcommand(s)
37-
38-
DISCUSSION:
39-
Rustup installs The Rust Programming Language from the official
40-
release channels, enabling you to easily switch between stable,
41-
beta, and nightly compilers and keep them updated. It makes
42-
cross-compiling simpler with binary builds of the standard library
43-
for common platforms.
44-
45-
If you are new to Rust consider running `rustup doc --book` to
46-
learn Rust.
47-
"""
4+
stdout = ""
485
stderr = """
49-
error: To override the toolchain using the 'rustup +toolchain' syntax, make sure to prefix the toolchain override with a '+'
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 '+'
507
8+
For more information try --help
519
"""

tests/suite/cli_misc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,10 @@ fn override_by_toolchain_on_the_command_line() {
946946
);
947947
config.expect_err(
948948
&["rustup", "@stable", "which", "rustc"],
949-
r#"Invalid value "@stable" for '<+toolchain>': Toolchain overrides must begin with '+'"#,
949+
"Invalid value \"@stable\" for '<+toolchain>': \"@stable\" is not a valid subcommand, \
950+
so it was interpreted as a toolchain name, but it is also invalid. \
951+
To override the toolchain using the 'rustup +toolchain' syntax, \
952+
make sure to prefix the toolchain override with a '+'",
950953
);
951954
config.expect_stderr_ok(
952955
&["rustup", "+stable", "set", "profile", "minimal"],

0 commit comments

Comments
 (0)