feat(help): Add styling to help output #12578
Conversation
|
r? @weihanglo (rustbot has picked a reviewer for you, use r? to override) |
|
Before applying this to the rest of cargo's commands, I figured I'd post this draft for feedback from the cargo team on (1) if we want this and (2) if we should make any tweaks |
3d0d622 to
0fb78ce
Compare
In working on rust-lang#12578, I'm focusing on each help string to decide how it should be handled and I noticed this. It feels weird to explain something in terms of another command's CLI, so I took `rustc --help`s message and added `rustc` to clarify it. In reflecting on this, I'm not 100% convinced and am open to other opinions.
In working on rust-lang#12578, I'm focusing on each help string to decide how it should be handled and I noticed this. It feels weird to explain something in terms of another command's CLI, so I took `rustc --help`s message and added `rustc` to clarify it. Looking back, the flag was added in rust-lang#2551 with the message we have today. Nothing seems to really be said about it. In reflecting on this, I'm not 100% convinced and am open to other opinions.
In working on rust-lang#12578, I felt it would be weird to style the entire statement about commands but it also felt weird to not style it. So this change explores and alternatively way of communicating the information.
In working on rust-lang#12578, I felt it would be weird to style the entire statement about commands but it also felt weird to not style it. So this change explores an alternatively way of communicating the information.
fix(help): Explain --explain In working on #12578, I'm focusing on each help string to decide how it should be handled and I noticed this. It feels weird to explain something in terms of another command's CLI, so I took `rustc --help`s message and added `rustc` to clarify it. Looking back, the flag was added in #2551 with the message we have today. Nothing seems to really be said about it. In reflecting on this, I'm not 100% convinced and am open to other opinions.
Auditing all of the `--help` in prep for rust-lang#12578 and noticed that we list the VCS information twice, once on our end and once by clap.
fix(help): Remove redundant information from new/init Auditing all of the `--help` in prep for #12578 and noticed that we list the VCS information twice, once on our end and once by clap.
In working on rust-lang#12578, I'm focusing on each help string to decide how it should be handled and I noticed this. It feels weird to explain something in terms of another command's CLI, so I took `rustc --help`s message and added `rustc` to clarify it. Looking back, the flag was added in rust-lang#2551 with the message we have today. Nothing seems to really be said about it. In reflecting on this, I'm not 100% convinced and am open to other opinions.
fix(help): Explain --explain In working on #12578, I'm focusing on each help string to decide how it should be handled and I noticed this. It feels weird to explain something in terms of another command's CLI, so I took `rustc --help`s message and added `rustc` to clarify it. Looking back, the flag was added in #2551 with the message we have today. Nothing seems to really be said about it. In reflecting on this, I'm not 100% convinced and am open to other opinions.
In working on rust-lang#12578, I felt it would be weird to style the entire statement about commands but it also felt weird to not style it. So this change explores an alternatively way of communicating the information.
In working on rust-lang#12578, I felt it would be weird to style the entire statement about commands but it also felt weird to not style it. So this change explores an alternatively way of communicating the information.
fix(help): Provide better commands heading for styling In working on #12578, I felt it would be weird to style the entire statement about commands but it also felt weird to not style it. So this change explores an alternatively way of communicating the information.
|
☔ The latest upstream changes (presumably #12593) made this pull request unmergeable. Please resolve the merge conflicts. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
Let's merge it and see how people feel about it 🚀 @bors r+ |
|
☀️ Test successful - checks-actions |
|
How can I disable this or change the used colors?
|
|
Could you go into why you want to disable it? It matches existing cargo colors so we thought it'd be innocuous. It'd be good to know what problems people are having with it. As for disabling, the cli doesn't work because help gets processed before we can process |
|
Thanks for calling them out. Some relevant contexts here about why it is hacky to support the option in CLI options and
That said, this is a thing I would like to see it fixed. |
Note that we are using terminal-configured colors, rather than something like RGB, so you do have full control over how this gets rendered in your terminal. |
|
@epage Strictly speaking, the problem is not the color itself. I feel some inconsistency in how the color is used:
Anyway, the essential problem is all of the Rust users with different personal preferences are now forced to be exposed to the colorful output. |
The reason I chose those colors for the help is that Green is used as more of a primary header while Cyan is a lower header / note.
Usually a command-line flag is for transient behavior. If this is for user preference, a CLI flag wouldn't be appropriate. As there are related issues for this., I'd recommend we shift the focus to the relevant ones as anything discussed here will be lost track of. |
I don't think so. This is also a personal preference for design, I think. function cargo() {
if [[ $1 == 'build' ]]; then
command cargo build --color never "$@"
else
command cargo "$@"
fi
}whether or not this is the way how
I do agree. Thank you for the series of the replies. |


What does this PR try to resolve?
Try to make
--helpoutput easier to parse by using terminal stylingScreenshots:
(
nargois my shell script wrappingcargo run --manifest-path cargo/Cargo.toml)How should we test and review this PR?
At this time, the only styling snapshotting library I know of is a pain to use, so testing this requires manually running the commands which I did. Screenshots are included for easier evaluation of the general idea.
Snapshotting of the plain text output ensures we don't have accidental formatting regressions from this change since the formatting isn't as obvious from looking at the code.
Additional information
Traditionally, cargo has disabled clap's styled output. My assumed
reason is that cargo mixes custom help output with auto-generated and
you couldn't previously make it all styled.
Clap 4.2 allowed users to pass in strings styled using ANSI escape
codes, allowing us to pass in styled text that matches clap, unblocking this. In clap
4.4.1, clap gained the ability for the user to override the style.
In this PR, I decided to use the new 4.4.1 feature to style clap's
output to match the rest of cargo's output. Alternatively, we could use
a more subdue style that clap uses by default.
I used the
color-printcrate to allow something almost html-like for styling&static str. Alternatively, we could directly embed the ANSI escape codes harder to get write, harder to inspect), or we could do the styling at runtime and enable thestringfeature in clap.I decided to not style
Arg::helpmessages becausechristmas tree
The one exception I made was for
--listsince it is for apsuedo-command (
...) and I wanted to intentionally draw attention toit.
#12593 made styling of
cargo -hcleaner imo.#12592 and #12594 were improvements I noticed while doing this.