Skip to content

[CLI] Pretty-print --help with ANSI styling#4192

Open
Wauplin wants to merge 10 commits intomainfrom
cursor/pretty-help-9c69
Open

[CLI] Pretty-print --help with ANSI styling#4192
Wauplin wants to merge 10 commits intomainfrom
cursor/pretty-help-9c69

Conversation

@Wauplin
Copy link
Copy Markdown
Contributor

@Wauplin Wauplin commented May 5, 2026

Related to private slack thread: https://huggingface.slack.com/archives/C0ACCEFPU9W/p1777986048386859

This PR highlights a bit more the sections and commands in the help section of the CLI.
Mainly:

  • underlined + bold section titles
  • bold options/commands

Also update ANSI helper to never return formatted strings when running in agent mode.

hf --help

image

hf upload --help

image

Slack Thread

Open in Web Open in Cursor 

Note

Low Risk
Low risk: changes are limited to CLI --help formatting and ANSI styling behavior (now disabled in agent/NO_COLOR contexts), with no impact on Hub API calls or data handling.

Overview
Improves hf ... --help readability by introducing a custom Click help formatter that underlines section headings and bolds option/command names, and wiring it in via a new StyledContext used by the main Typer group and generated commands.

Extends the ANSI terminal helper with underline() and ensures ANSI codes are never emitted when NO_COLOR is set or when running under a detected AI agent (is_agent()).

Reviewed by Cursor Bugbot for commit 9504648. Bugbot is set up for automated code reviews on this repo. Configure here.

Add a StyledHelpFormatter that applies ANSI formatting to CLI help:
- Bold section headings (Options:, Commands:, etc.)
- Yellow 'Usage:' prefix with bold program name
- Cyan command/option names in definition lists
- Dim example lines ($ hf ...)
- Bold epilog headings (Examples, Learn more)

ANSI codes are only emitted when stdout is a TTY, the process
is not driven by an AI agent, and NO_COLOR is not set.

Co-authored-by: Lucain <Wauplin@users.noreply.github.com>
@bot-ci-comment
Copy link
Copy Markdown

bot-ci-comment Bot commented May 5, 2026

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

cursoragent and others added 3 commits May 5, 2026 15:43
- Replace raw ANSI escape codes with the existing ANSI utility class
- Add ANSI.dim() to the shared helper
- Remove cyan styling from definition list entries
- Fix false-positive bolding of description text (only bold
  epilog headings at indent level 0)

Co-authored-by: Lucain <Wauplin@users.noreply.github.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit dc1ba71. Configure here.

Comment thread src/huggingface_hub/cli/_help_formatter.py Outdated
@Wauplin Wauplin marked this pull request as ready for review May 6, 2026 09:53
@Wauplin Wauplin requested review from hanouticelina and julien-c May 6, 2026 09:53
@julien-c
Copy link
Copy Markdown
Member

julien-c commented May 6, 2026

i like it!!

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