Skip to content

Commit 66ca40d

Browse files
epagedjc
authored andcommitted
feat(cli): Have Help Discussions match rest of CLI Help
1 parent 25dfef2 commit 66ca40d

19 files changed

+136
-108
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ anstyle = "1.0.11"
4646
anyhow = "1.0.69"
4747
cfg-if = "1.0"
4848
chrono = { version = "0.4", default-features = false, features = ["std"] }
49-
clap = { version = "4", features = ["derive", "wrap_help"] }
49+
clap = { version = "4", features = ["derive", "wrap_help", "string"] }
5050
clap-cargo = "0.18.2"
5151
clap_complete = "4"
5252
console = "0.16"

src/cli/help.rs

Lines changed: 87 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
pub(crate) fn rustup_help() -> &'static str {
2-
r"Discussion:
1+
use clap_cargo::style::{HEADER, LITERAL, PLACEHOLDER};
2+
3+
pub(crate) fn rustup_help() -> String {
4+
format!(
5+
r"{HEADER}Discussion:{HEADER:#}
36
Rustup installs The Rust Programming Language from the official
47
release channels, enabling you to easily switch between stable,
58
beta, and nightly compilers and keep them updated. It makes
@@ -8,71 +11,83 @@ pub(crate) fn rustup_help() -> &'static str {
811
912
If you are new to Rust consider running `rustup doc --book` to
1013
learn Rust."
14+
)
1115
}
1216

13-
pub(crate) fn show_help() -> &'static str {
14-
r"Discussion:
17+
pub(crate) fn show_help() -> String {
18+
format!(
19+
r"{HEADER}Discussion:{HEADER:#}
1520
Shows the name of the active toolchain and the version of `rustc`.
1621
1722
If the active toolchain has installed support for additional
1823
compilation targets, then they are listed as well.
1924
2025
If there are multiple toolchains installed then all installed
2126
toolchains are listed as well."
27+
)
2228
}
2329

24-
pub(crate) fn show_active_toolchain_help() -> &'static str {
25-
r"Discussion:
30+
pub(crate) fn show_active_toolchain_help() -> String {
31+
format!(
32+
r"{HEADER}Discussion:{HEADER:#}
2633
Shows the name of the active toolchain.
2734
2835
This is useful for figuring out the active tool chain from
2936
scripts.
3037
3138
You should use `rustc --print sysroot` to get the sysroot, or
3239
`rustc --version` to get the toolchain version."
40+
)
3341
}
3442

35-
pub(crate) fn update_help() -> &'static str {
36-
r"Discussion:
43+
pub(crate) fn update_help() -> String {
44+
format!(
45+
r"{HEADER}Discussion:{HEADER:#}
3746
With no toolchain specified, the `update` command updates each of
3847
the installed toolchains from the official release channels, then
3948
updates rustup itself.
4049
4150
If given a toolchain argument then `update` updates that
4251
toolchain, the same as `rustup toolchain install`."
52+
)
4353
}
4454

45-
pub(crate) fn install_help() -> &'static str {
46-
r"Discussion:
55+
pub(crate) fn install_help() -> String {
56+
format!(
57+
r"{HEADER}Discussion:{HEADER:#}
4758
Installs a specific rust toolchain.
4859
4960
The 'install' command is an alias for 'rustup update <toolchain>'."
61+
)
5062
}
5163

52-
pub(crate) fn default_help() -> &'static str {
53-
r"Discussion:
64+
pub(crate) fn default_help() -> String {
65+
format!(
66+
r"{HEADER}Discussion:{HEADER:#}
5467
Sets the default toolchain to the one specified. If the toolchain
5568
is not already installed then it is installed first."
69+
)
5670
}
5771

58-
pub(crate) fn toolchain_help() -> &'static str {
59-
r"Discussion:
72+
pub(crate) fn toolchain_help() -> String {
73+
format!(
74+
r"{HEADER}Discussion:{HEADER:#}
6075
Many `rustup` commands deal with *toolchains*, a single
6176
installation of the Rust compiler. `rustup` supports multiple
6277
types of toolchains. The most basic track the official release
63-
channels: 'stable', 'beta' and 'nightly'} but `rustup` can also
78+
channels: 'stable', 'beta' and 'nightly'; but `rustup` can also
6479
install specific toolchains from the official archives, toolchains for
6580
alternate host platforms, and from local builds ('custom toolchains').
6681
6782
Standard release channel toolchain names have the following form:
6883
69-
<channel>[-<date>][-<host>]
84+
{PLACEHOLDER}<channel>[-<date>][-<host>]{PLACEHOLDER:#}
7085
71-
<channel> = stable|beta|nightly|<versioned>[-<prerelease>]
72-
<versioned> = <major.minor>|<major.minor.patch>
73-
<prerelease> = beta[.<number>]
74-
<date> = YYYY-MM-DD
75-
<host> = <target-triple>
86+
{PLACEHOLDER}<channel> = stable|beta|nightly|<versioned>[-<prerelease>]{PLACEHOLDER:#}
87+
{PLACEHOLDER}<versioned> = <major.minor>|<major.minor.patch>{PLACEHOLDER:#}
88+
{PLACEHOLDER}<prerelease> = beta[.<number>]{PLACEHOLDER:#}
89+
{PLACEHOLDER}<date> = YYYY-MM-DD{PLACEHOLDER:#}
90+
{PLACEHOLDER}<host> = <target-triple>{PLACEHOLDER:#}
7691
7792
'channel' is a named release channel, a major and minor version
7893
number such as `1.42`, or a fully specified version number, such
@@ -84,25 +99,27 @@ pub(crate) fn toolchain_help() -> &'static str {
8499
for installing a 32-bit compiler on a 64-bit platform, or for
85100
installing the [MSVC-based toolchain] on Windows. For example:
86101
87-
$ rustup toolchain install stable-x86_64-pc-windows-msvc
102+
{LITERAL}$ rustup toolchain install stable-x86_64-pc-windows-msvc{LITERAL:#}
88103
89104
For convenience, omitted elements of the target triple will be
90105
inferred, so the above could be written:
91106
92-
$ rustup toolchain install stable-msvc
107+
{LITERAL}$ rustup toolchain install stable-msvc{LITERAL:#}
93108
94109
The `rustup default` command may be used to both install and set
95110
the desired toolchain as default in a single command:
96111
97-
$ rustup default stable-msvc
112+
{LITERAL}$ rustup default stable-msvc{LITERAL:#}
98113
99114
rustup can also manage symlinked local toolchain builds, which are
100115
often used for developing Rust itself. For more information see
101116
`rustup toolchain help link`."
117+
)
102118
}
103119

104-
pub(crate) fn toolchain_link_help() -> &'static str {
105-
r"Discussion:
120+
pub(crate) fn toolchain_link_help() -> String {
121+
format!(
122+
r"{HEADER}Discussion:{HEADER:#}
106123
'toolchain' is the custom name to be assigned to the new toolchain.
107124
Any name is permitted as long as:
108125
- it does not include '/' or '\' except as the last character
@@ -117,15 +134,17 @@ pub(crate) fn toolchain_link_help() -> &'static str {
117134
the build directory. After building, you can test out different
118135
compiler versions as follows:
119136
120-
$ rustup toolchain link latest-stage1 build/x86_64-unknown-linux-gnu/stage1
121-
$ rustup override set latest-stage1
137+
{LITERAL}$ rustup toolchain link latest-stage1 build/x86_64-unknown-linux-gnu/stage1{LITERAL:#}
138+
{LITERAL}$ rustup override set latest-stage1{LITERAL:#}
122139
123140
If you now compile a crate in the current directory, the custom
124141
toolchain 'latest-stage1' will be used."
142+
)
125143
}
126144

127-
pub(crate) fn override_help() -> &'static str {
128-
r"Discussion:
145+
pub(crate) fn override_help() -> String {
146+
format!(
147+
r"{HEADER}Discussion:{HEADER:#}
129148
Overrides configure Rustup to use a specific toolchain when
130149
running in a specific directory.
131150
@@ -136,28 +155,32 @@ pub(crate) fn override_help() -> &'static str {
136155
137156
To pin to a specific nightly:
138157
139-
$ rustup override set nightly-2014-12-18
158+
{LITERAL}$ rustup override set nightly-2014-12-18{LITERAL:#}
140159
141160
Or a specific stable release:
142161
143-
$ rustup override set 1.0.0
162+
{LITERAL}$ rustup override set 1.0.0{LITERAL:#}
144163
145164
To see the active toolchain use `rustup show`. To remove the
146165
override and use the default toolchain again, `rustup override
147166
unset`."
167+
)
148168
}
149169

150-
pub(crate) fn override_unset_help() -> &'static str {
151-
r"Discussion:
170+
pub(crate) fn override_unset_help() -> String {
171+
format!(
172+
r"{HEADER}Discussion:{HEADER:#}
152173
If `--path` argument is present, removes the override toolchain
153174
for the specified directory. If `--nonexistent` argument is
154175
present, removes the override toolchain for all nonexistent
155176
directories. Otherwise, removes the override toolchain for the
156177
current directory."
178+
)
157179
}
158180

159-
pub(crate) fn run_help() -> &'static str {
160-
r"Discussion:
181+
pub(crate) fn run_help() -> String {
182+
format!(
183+
r"{HEADER}Discussion:{HEADER:#}
161184
Configures an environment to use the given toolchain and then runs
162185
the specified program. The command may be any program, not just
163186
rustc or cargo. This can be used for testing arbitrary toolchains
@@ -168,22 +191,26 @@ pub(crate) fn run_help() -> &'static str {
168191
can be set by using `+toolchain` as the first argument. These are
169192
equivalent:
170193
171-
$ cargo +nightly build
194+
{LITERAL}$ cargo +nightly build{LITERAL:#}
172195
173-
$ rustup run nightly cargo build"
196+
{LITERAL}$ rustup run nightly cargo build{LITERAL:#}"
197+
)
174198
}
175199

176-
pub(crate) fn doc_help() -> &'static str {
177-
r"Discussion:
200+
pub(crate) fn doc_help() -> String {
201+
format!(
202+
r"{HEADER}Discussion:{HEADER:#}
178203
Opens the documentation for the currently active toolchain with
179204
the default browser.
180205
181206
By default, it opens the documentation index. Use the various
182207
flags to open specific pieces of documentation."
208+
)
183209
}
184210

185-
pub(crate) fn completions_help() -> &'static str {
186-
r"Discussion:
211+
pub(crate) fn completions_help() -> String {
212+
format!(
213+
r"{HEADER}Discussion:{HEADER:#}
187214
Enable tab completion for Bash, Fish, Zsh, or PowerShell
188215
The script is output on `stdout`, allowing one to re-direct the
189216
output to the file of their choosing. Where you place the file
@@ -201,8 +228,8 @@ pub(crate) fn completions_help() -> &'static str {
201228
`~/.local/share/bash-completion/completions` for user-specific commands.
202229
Run the command:
203230
204-
$ mkdir -p ~/.local/share/bash-completion/completions
205-
$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup
231+
{LITERAL}$ mkdir -p ~/.local/share/bash-completion/completions{LITERAL:#}
232+
{LITERAL}$ rustup completions bash > ~/.local/share/bash-completion/completions/rustup{LITERAL:#}
206233
207234
This installs the completion script. You may have to log out and
208235
log back in to your shell session for the changes to take effect.
@@ -212,16 +239,16 @@ pub(crate) fn completions_help() -> &'static str {
212239
Homebrew stores bash completion files within the Homebrew directory.
213240
With the `bash-completion` brew formula installed, run the command:
214241
215-
$ mkdir -p $(brew --prefix)/etc/bash_completion.d
216-
$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion
242+
{LITERAL}$ mkdir -p $(brew --prefix)/etc/bash_completion.d{LITERAL:#}
243+
{LITERAL}$ rustup completions bash > $(brew --prefix)/etc/bash_completion.d/rustup.bash-completion{LITERAL:#}
217244
218245
Fish:
219246
220247
Fish completion files are commonly stored in
221248
`$HOME/.config/fish/completions`. Run the command:
222249
223-
$ mkdir -p ~/.config/fish/completions
224-
$ rustup completions fish > ~/.config/fish/completions/rustup.fish
250+
{LITERAL}$ mkdir -p ~/.config/fish/completions{LITERAL:#}
251+
{LITERAL}$ rustup completions fish > ~/.config/fish/completions/rustup.fish{LITERAL:#}
225252
226253
This installs the completion script. You may have to log out and
227254
log back in to your shell session for the changes to take effect.
@@ -234,25 +261,25 @@ pub(crate) fn completions_help() -> &'static str {
234261
own to this list.
235262
236263
Adding a custom directory is often the safest bet if you are
237-
unsure of which directory to use. First create the directory} for
264+
unsure of which directory to use. First create the directory; for
238265
this example we'll create a hidden directory inside our `$HOME`
239266
directory:
240267
241-
$ mkdir ~/.zfunc
268+
{LITERAL}$ mkdir ~/.zfunc{LITERAL:#}
242269
243270
Then add the following lines to your `.zshrc` just before
244271
`compinit`:
245272
246-
fpath+=~/.zfunc
273+
{LITERAL}fpath+=~/.zfunc{LITERAL:#}
247274
248275
Now you can install the completions script using the following
249276
command:
250277
251-
$ rustup completions zsh > ~/.zfunc/_rustup
278+
{LITERAL}$ rustup completions zsh > ~/.zfunc/_rustup{LITERAL:#}
252279
253280
You must then either log out and log back in, or simply run
254281
255-
$ exec zsh
282+
{LITERAL}$ exec zsh{LITERAL:#}
256283
257284
for the new completions to take effect.
258285
@@ -272,21 +299,21 @@ pub(crate) fn completions_help() -> &'static str {
272299
273300
First, check if a profile has already been set
274301
275-
PS C:\> Test-Path $profile
302+
{LITERAL}PS C:\> Test-Path $profile{LITERAL:#}
276303
277304
If the above command returns `False` run the following
278305
279-
PS C:\> New-Item -path $profile -type file -force
306+
{LITERAL}PS C:\> New-Item -path $profile -type file -force{LITERAL:#}
280307
281308
Now open the file provided by `$profile` (if you used the
282309
`New-Item` command it will be
283-
`${env:USERPROFILE}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`
310+
`${{env:USERPROFILE}}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`
284311
285312
Next, we either save the completions file into our profile, or
286313
into a separate file and source it inside our profile. To save the
287314
completions into our profile simply use
288315
289-
PS C:\> rustup completions powershell >> ${env:USERPROFILE}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
316+
{LITERAL}PS C:\> rustup completions powershell >> ${{env:USERPROFILE}}\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1{LITERAL:#}
290317
291318
Cargo:
292319
@@ -297,11 +324,12 @@ pub(crate) fn completions_help() -> &'static str {
297324
298325
Bash:
299326
300-
$ rustup completions bash cargo >> ~/.local/share/bash-completion/completions/cargo
327+
{LITERAL}$ rustup completions bash cargo >> ~/.local/share/bash-completion/completions/cargo{LITERAL:#}
301328
302329
Zsh:
303330
304-
$ rustup completions zsh cargo > ~/.zfunc/_cargo"
331+
{LITERAL}$ rustup completions zsh cargo > ~/.zfunc/_cargo{LITERAL:#}"
332+
)
305333
}
306334

307335
pub(crate) fn official_toolchain_arg_help() -> &'static str {

0 commit comments

Comments
 (0)