Skip to content

Commit b579e23

Browse files
committed
Print help when a ValueValidation error occurs
Signed-off-by: hi-rustin <[email protected]>
1 parent 3438037 commit b579e23

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/cli/rustup_mode.rs

Lines changed: 14 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,15 @@ pub fn main() -> Result<utils::ExitCode> {
110114
write!(process().stdout().lock(), "{err}")?;
111115
return Ok(utils::ExitCode(1));
112116
}
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+
}
124+
return Ok(utils::ExitCode(1));
125+
}
113126
Err(err)
114127
}
115128
}?;
@@ -245,7 +258,7 @@ pub(crate) fn cli() -> Command<'static> {
245258
if s.starts_with('+') {
246259
Ok(s.to_owned())
247260
} else {
248-
Err("Toolchain overrides must begin with '+'".to_owned())
261+
Err(TOOLCHAIN_OVERRIDE_ERROR.to_owned())
249262
}
250263
}),
251264
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
bin.name = "rustup"
2+
args = ["random"]
3+
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+
"""
48+
stderr = """
49+
error: To override the toolchain using the 'rustup +toolchain' syntax, make sure to prefix the toolchain override with a '+'
50+
51+
"""

0 commit comments

Comments
 (0)