Skip to content

Commit 2e4faad

Browse files
epagedjc
authored andcommitted
refactor(cli): Switch help text to functions
1 parent 9c61986 commit 2e4faad

File tree

2 files changed

+102
-66
lines changed

2 files changed

+102
-66
lines changed

src/cli/help.rs

Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,66 @@
1-
pub(crate) static RUSTUP_HELP: &str = r"Discussion:
1+
pub(crate) fn rustup_help() -> &'static str {
2+
r"Discussion:
23
Rustup installs The Rust Programming Language from the official
34
release channels, enabling you to easily switch between stable,
45
beta, and nightly compilers and keep them updated. It makes
56
cross-compiling simpler with binary builds of the standard library
67
for common platforms.
78
89
If you are new to Rust consider running `rustup doc --book` to
9-
learn Rust.";
10+
learn Rust."
11+
}
1012

11-
pub(crate) static SHOW_HELP: &str = r"Discussion:
13+
pub(crate) fn show_help() -> &'static str {
14+
r"Discussion:
1215
Shows the name of the active toolchain and the version of `rustc`.
1316
1417
If the active toolchain has installed support for additional
1518
compilation targets, then they are listed as well.
1619
1720
If there are multiple toolchains installed then all installed
18-
toolchains are listed as well.";
21+
toolchains are listed as well."
22+
}
1923

20-
pub(crate) static SHOW_ACTIVE_TOOLCHAIN_HELP: &str = r"Discussion:
24+
pub(crate) fn show_active_toolchain_help() -> &'static str {
25+
r"Discussion:
2126
Shows the name of the active toolchain.
2227
2328
This is useful for figuring out the active tool chain from
2429
scripts.
2530
2631
You should use `rustc --print sysroot` to get the sysroot, or
27-
`rustc --version` to get the toolchain version.";
32+
`rustc --version` to get the toolchain version."
33+
}
2834

29-
pub(crate) static UPDATE_HELP: &str = r"Discussion:
35+
pub(crate) fn update_help() -> &'static str {
36+
r"Discussion:
3037
With no toolchain specified, the `update` command updates each of
3138
the installed toolchains from the official release channels, then
3239
updates rustup itself.
3340
3441
If given a toolchain argument then `update` updates that
35-
toolchain, the same as `rustup toolchain install`.";
42+
toolchain, the same as `rustup toolchain install`."
43+
}
3644

37-
pub(crate) static INSTALL_HELP: &str = r"Discussion:
45+
pub(crate) fn install_help() -> &'static str {
46+
r"Discussion:
3847
Installs a specific rust toolchain.
3948
40-
The 'install' command is an alias for 'rustup update <toolchain>'.";
49+
The 'install' command is an alias for 'rustup update <toolchain>'."
50+
}
4151

42-
pub(crate) static DEFAULT_HELP: &str = r"Discussion:
52+
pub(crate) fn default_help() -> &'static str {
53+
r"Discussion:
4354
Sets the default toolchain to the one specified. If the toolchain
44-
is not already installed then it is installed first.";
55+
is not already installed then it is installed first."
56+
}
4557

46-
pub(crate) static TOOLCHAIN_HELP: &str = r"Discussion:
58+
pub(crate) fn toolchain_help() -> &'static str {
59+
r"Discussion:
4760
Many `rustup` commands deal with *toolchains*, a single
4861
installation of the Rust compiler. `rustup` supports multiple
4962
types of toolchains. The most basic track the official release
50-
channels: 'stable', 'beta' and 'nightly'; but `rustup` can also
63+
channels: 'stable', 'beta' and 'nightly'} but `rustup` can also
5164
install specific toolchains from the official archives, toolchains for
5265
alternate host platforms, and from local builds ('custom toolchains').
5366
@@ -85,9 +98,11 @@ pub(crate) static TOOLCHAIN_HELP: &str = r"Discussion:
8598
8699
rustup can also manage symlinked local toolchain builds, which are
87100
often used for developing Rust itself. For more information see
88-
`rustup toolchain help link`.";
101+
`rustup toolchain help link`."
102+
}
89103

90-
pub(crate) static TOOLCHAIN_LINK_HELP: &str = r"Discussion:
104+
pub(crate) fn toolchain_link_help() -> &'static str {
105+
r"Discussion:
91106
'toolchain' is the custom name to be assigned to the new toolchain.
92107
Any name is permitted as long as:
93108
- it does not include '/' or '\' except as the last character
@@ -106,9 +121,11 @@ pub(crate) static TOOLCHAIN_LINK_HELP: &str = r"Discussion:
106121
$ rustup override set latest-stage1
107122
108123
If you now compile a crate in the current directory, the custom
109-
toolchain 'latest-stage1' will be used.";
124+
toolchain 'latest-stage1' will be used."
125+
}
110126

111-
pub(crate) static OVERRIDE_HELP: &str = r"Discussion:
127+
pub(crate) fn override_help() -> &'static str {
128+
r"Discussion:
112129
Overrides configure Rustup to use a specific toolchain when
113130
running in a specific directory.
114131
@@ -127,16 +144,20 @@ pub(crate) static OVERRIDE_HELP: &str = r"Discussion:
127144
128145
To see the active toolchain use `rustup show`. To remove the
129146
override and use the default toolchain again, `rustup override
130-
unset`.";
147+
unset`."
148+
}
131149

132-
pub(crate) static OVERRIDE_UNSET_HELP: &str = r"Discussion:
150+
pub(crate) fn override_unset_help() -> &'static str {
151+
r"Discussion:
133152
If `--path` argument is present, removes the override toolchain
134153
for the specified directory. If `--nonexistent` argument is
135154
present, removes the override toolchain for all nonexistent
136155
directories. Otherwise, removes the override toolchain for the
137-
current directory.";
156+
current directory."
157+
}
138158

139-
pub(crate) static RUN_HELP: &str = r"Discussion:
159+
pub(crate) fn run_help() -> &'static str {
160+
r"Discussion:
140161
Configures an environment to use the given toolchain and then runs
141162
the specified program. The command may be any program, not just
142163
rustc or cargo. This can be used for testing arbitrary toolchains
@@ -149,16 +170,20 @@ pub(crate) static RUN_HELP: &str = r"Discussion:
149170
150171
$ cargo +nightly build
151172
152-
$ rustup run nightly cargo build";
173+
$ rustup run nightly cargo build"
174+
}
153175

154-
pub(crate) static DOC_HELP: &str = r"Discussion:
176+
pub(crate) fn doc_help() -> &'static str {
177+
r"Discussion:
155178
Opens the documentation for the currently active toolchain with
156179
the default browser.
157180
158181
By default, it opens the documentation index. Use the various
159-
flags to open specific pieces of documentation.";
182+
flags to open specific pieces of documentation."
183+
}
160184

161-
pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
185+
pub(crate) fn completions_help() -> &'static str {
186+
r"Discussion:
162187
Enable tab completion for Bash, Fish, Zsh, or PowerShell
163188
The script is output on `stdout`, allowing one to re-direct the
164189
output to the file of their choosing. Where you place the file
@@ -209,7 +234,7 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
209234
own to this list.
210235
211236
Adding a custom directory is often the safest bet if you are
212-
unsure of which directory to use. First create the directory; for
237+
unsure of which directory to use. First create the directory} for
213238
this example we'll create a hidden directory inside our `$HOME`
214239
directory:
215240
@@ -276,22 +301,33 @@ pub(crate) static COMPLETIONS_HELP: &str = r"Discussion:
276301
277302
Zsh:
278303
279-
$ rustup completions zsh cargo > ~/.zfunc/_cargo";
304+
$ rustup completions zsh cargo > ~/.zfunc/_cargo"
305+
}
280306

281-
pub(crate) static OFFICIAL_TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
307+
pub(crate) fn official_toolchain_arg_help() -> &'static str {
308+
"Toolchain name, such as 'stable', 'nightly', \
282309
or '1.8.0'. For more information see `rustup \
283-
help toolchain`";
284-
pub(crate) static RESOLVABLE_LOCAL_TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
310+
help toolchain`"
311+
}
312+
pub(crate) fn resolvable_local_toolchain_arg_help() -> &'static str {
313+
"Toolchain name, such as 'stable', 'nightly', \
285314
'1.8.0', or a custom toolchain name, or an absolute path. For more \
286-
information see `rustup help toolchain`";
287-
pub(crate) static RESOLVABLE_TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
315+
information see `rustup help toolchain`"
316+
}
317+
pub(crate) fn resolvable_toolchain_arg_help() -> &'static str {
318+
"Toolchain name, such as 'stable', 'nightly', \
288319
'1.8.0', or a custom toolchain name. For more information see `rustup \
289-
help toolchain`";
290-
pub(crate) static MAYBE_RESOLVABLE_TOOLCHAIN_ARG_HELP: &str = "'none', a toolchain name, such as 'stable', 'nightly', \
320+
help toolchain`"
321+
}
322+
pub(crate) fn maybe_resolvable_toolchain_arg_help() -> &'static str {
323+
"'none', a toolchain name, such as 'stable', 'nightly', \
291324
'1.8.0', or a custom toolchain name. For more information see `rustup \
292-
help toolchain`";
325+
help toolchain`"
326+
}
293327

294-
pub(crate) static TOPIC_ARG_HELP: &str = "Topic such as 'core', 'fn', 'usize', 'eprintln!', \
328+
pub(crate) fn topic_arg_help() -> &'static str {
329+
"Topic such as 'core', 'fn', 'usize', 'eprintln!', \
295330
'core::arch', 'alloc::format!', 'std::fs', \
296331
'std::fs::read_dir', 'std::io::Bytes', \
297-
'std::iter::Sum', 'std::io::error::Result' etc...";
332+
'std::iter::Sum', 'std::io::error::Result' etc..."
333+
}

0 commit comments

Comments
 (0)