Skip to content

Conversation

@epage
Copy link
Contributor

@epage epage commented Oct 20, 2025

This adds styling to clap help and errors to make it easier to scan. This uses Cargo's styling (via clap-cargo) for consistency across the project.

  • For consistency, my main priorities are end-user commands like rustup and cargo and not plumbing commands like rustfmt and rustc.
  • We've not yet decided how to handle this through an official crate, so doing it unofficially for now.

To ensure consistency, the Discussion sections were updated.

  • I was limited in my use of color within Discussion to match at least the initial approach we've taken in Cargo. I worry that if we color every literal, placeholder, etc then it will be a sea of colors and lose the benefit. Instead color is limited to items we want to draw extra attention to or visually big items to help set them apart
  • Cargo doesn't have sub-headers, so I had to define that myself for rustup completions
  • I could have used something like color-print to do the styling at compile time but that would require duplicating Cargo's styling which would have been harder to maintain. Instead, we style at runtime so we can use clap-cargo.

@epage epage marked this pull request as draft October 20, 2025 11:38
Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

Copy link
Member

@rami3l rami3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might indeed want to address https://rust-lang.zulipchat.com/#narrow/channel/490103-t-rustup/topic/More.20rustup.2Fcargo.2Frustc.20consistency/near/545410015 in addition.

Otherwise this looks pretty nice, thanks!

@epage epage marked this pull request as ready for review October 20, 2025 15:28
@epage
Copy link
Contributor Author

epage commented Oct 20, 2025

Everything should now be styled.

epage added a commit to epage/rustup that referenced this pull request Oct 20, 2025
This is based on review feedback from rust-lang#4551.

I experimented with a `clippy.toml` file for "blessing" some of these,
like `errors`, but for some reason I wasn't able to get it to work.
src/cli/help.rs Outdated
use anstyle::Style;
use clap_cargo::style::{HEADER, LITERAL, PLACEHOLDER};

const SUBHEADER: Style = Style::new().bold();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: sorry, one more that I forgot in the last round: please put this at the bottom.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went ahead and did this but this is one of the rare cases where it feels better at the top to me.

In general, the way I view organizing a source file is it should act like a tree with the top item(s) at the top and branch out from there, so the top item(s) act as a ToC and provide context. In that case, constants are noise. However, in this case, this has all of the styling elements together and now we're splitting them up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find that a very strong argument. Lots of modules where some items are imported while other items are defined near the bottom.

epage added a commit to epage/rustup that referenced this pull request Oct 20, 2025
This is based on review feedback from rust-lang#4551.

I experimented with a `clippy.toml` file for "blessing" some of these,
like `errors`, but for some reason I wasn't able to get it to work.
@djc djc added this pull request to the merge queue Oct 21, 2025
Merged via the queue into rust-lang:main with commit 32141c9 Oct 21, 2025
29 checks passed
epage added a commit to epage/rustup that referenced this pull request Oct 21, 2025
This is based on review feedback from rust-lang#4551.

I experimented with a `clippy.toml` file for "blessing" some of these,
like `errors`, but for some reason I wasn't able to get it to work.
@epage epage deleted the clap branch October 21, 2025 13:59
@epage epage mentioned this pull request Oct 21, 2025
github-merge-queue bot pushed a commit that referenced this pull request Oct 21, 2025
This is based on review feedback from #4551.

I experimented with a `clippy.toml` file for "blessing" some of these,
like `errors`, but for some reason I wasn't able to get it to work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants