Skip to content

Fix HelpFormatter.write_usage with empty args producing no output#3433

Closed
driphtyio wants to merge 1 commit into
pallets:mainfrom
driphtyio:main
Closed

Fix HelpFormatter.write_usage with empty args producing no output#3433
driphtyio wants to merge 1 commit into
pallets:mainfrom
driphtyio:main

Conversation

@driphtyio
Copy link
Copy Markdown

Fixes #3360

Problem

When write_usage is called with no args (the default ""), wrap_text("") produces an empty string, so no usage line is printed at all.

Reproduction

import click
f = click.HelpFormatter()
f.write_usage("program")
print(f.getvalue())  # empty line instead of "Usage: program\n"

Fix

Added an early return that writes prefix + prog directly when args is empty or falsy. This avoids passing an empty string to wrap_text.

When write_usage is called with no args (the default), wrap_text('')
produces an empty string, so no usage line is printed at all.

Fixed by adding an early return that writes the prefix + prog directly
when args is empty.

Fixes pallets#3360
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.

Empty output from HelpFormatter.write_usage for a program without arguments

3 participants