Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.. currentmodule:: click

Version 8.3.3
--------------

- Fix ``HelpFormatter.write_usage()`` dropping the usage line when called
without any arguments. :issue:`3360`

Version 8.3.2
--------------

Expand Down
9 changes: 8 additions & 1 deletion src/click/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,14 @@ def write_usage(self, prog: str, args: str = "", prefix: str | None = None) -> N
if prefix is None:
prefix = f"{_('Usage:')} "

usage_prefix = f"{prefix:>{self.current_indent}}{prog} "
usage_prefix = f"{prefix:>{self.current_indent}}{prog}"

if not args:
self.write(usage_prefix)
self.write("\n")
return

usage_prefix = f"{usage_prefix} "
text_width = self.width - self.current_indent

if text_width >= (term_len(usage_prefix) + 20):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,9 @@ def test_help_formatter_write_text():
actual = formatter.getvalue()
expected = " Lorem ipsum dolor sit amet,\n consectetur adipiscing elit\n"
assert actual == expected


def test_help_formatter_write_usage_without_args():
formatter = click.formatting.HelpFormatter()
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

For consistency within this test module, consider instantiating the formatter via the public alias click.HelpFormatter() (used in test_help_formatter_write_text) instead of reaching into click.formatting.HelpFormatter(). This keeps tests aligned with the intended public API surface.

Suggested change
formatter = click.formatting.HelpFormatter()
formatter = click.HelpFormatter()

Copilot uses AI. Check for mistakes.
formatter.write_usage("program")
assert formatter.getvalue() == "Usage: program\n"
Loading