`HelpFormatter.write_usage` breaks options at a hyphen

Aperta Adatta ai principianti
#3,362 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@kdeldycke ci sta già lavorando.

Dal 2/11/2026.

  • #3385 di @cyphercodes — chiusa senza merge
  • #3388 di @charlieleith — chiusa senza merge
  • #3399 di @MackDing — chiusa senza merge
  • #3411 di @lihan3238 — chiusa senza merge
  • #3414 di @kimjune01 — chiusa senza merge
  • #3425 di @RajvardhanPatil07 — chiusa senza merge
  • #3437 di @c-tonneslan — chiusa senza merge
  • #3441 di @goutamadwant — chiusa senza merge
  • #3518 di @thakoreh — chiusa senza merge
  • #3902 di @kdeldycke — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Inizia da click.HelpFormatter.write_usage e dal relativo percorso wrap_text, quindi esegui la riproduzione Python fornita con width 65. Verifica l’output rispetto al testo di utilizzo previsto e aggiungi una copertura che dimostri che le opzioni con trattini rimangono intere ai limiti di riga, mentre il ritorno a capo continua a rispettare la larghezza configurata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

help output

If an option containing a hyphen in its name is printed at the line break limit, it’s broken at the hyphen.

Reproduction
import click

options = [
    "--enable-verbose-logging",
    "--output-file-path",
    "--max-retry-count",
    "--disable-cache-mode",
    "--config-file-location",
    "--user-auth-token",
    "--auto-update-interval",
    "--force-overwrite-existing",
    "--network-timeout-seconds",
    "--debug-trace-enabled",
]

f = click.HelpFormatter(width=65)
f.write_usage("program", " ".join(options))
print(f.getvalue())
Expected output
Usage: program --enable-verbose-logging --output-file-path
               --max-retry-count --disable-cache-mode
               --config-file-location --user-auth-token
               --auto-update-interval --force-overwrite-existing
               --network-timeout-seconds --debug-trace-enabled
Actual output
Usage: program --enable-verbose-logging --output-file-path --max-
               retry-count --disable-cache-mode --config-file-
               location --user-auth-token --auto-update-interval
               --force-overwrite-existing --network-timeout-
               seconds --debug-trace-enabled
Environment
  • Python version: 3.12.3
  • Click version: 8.3.1
Additional information
width option

This also happens without specifying width. The width option is altered in the example to make the issue more frequent.

Relevance to other use cases

This may likely only affect:

  • direct users of click.HelpFormatter,
  • users of click.argument with custom metavar containing hyphens.

On the other hand, click prints [OPTIONS] instead of listing individual options on the usage line and uses underscores instead of hyphens in argument names (unless specifying metavar).

Cause

I looked into the code and found that textwrap.TextWrapper is used under the hood, which has the break_on_hyphens option. However, there is no option for the click user to influence this, apart from reimplementing HelpFormatter.write_usage (in a subclass) and wrap_text.

Lingua principale
Python
Stelle
17.8k
Fork
3.3k
Merge medio
3g 3h
PR unite (30g)
13

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pallets/click

Tutte le issue di pallets/click

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.