`HelpFormatter.write_usage` breaks options at a hyphen
Maintainer thường phản hồi trong vòng 1 ngày
@kdeldycke đang làm issue này rồi.
Từ ngày 2/11/2026.
- #3385 của @cyphercodes — đã đóng, không merge
- #3388 của @charlieleith — đã đóng, không merge
- #3399 của @MackDing — đã đóng, không merge
- #3411 của @lihan3238 — đã đóng, không merge
- #3414 của @kimjune01 — đã đóng, không merge
- #3425 của @RajvardhanPatil07 — đã đóng, không merge
- #3437 của @c-tonneslan — đã đóng, không merge
- #3441 của @goutamadwant — đã đóng, không merge
- #3518 của @thakoreh — đã đóng, không merge
- #3902 của @kdeldycke — đang mở
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
Hướng nghiên cứu
Bắt đầu tại click.HelpFormatter.write_usage và đường dẫn wrap_text của nó, sau đó chạy bản tái hiện Python được cung cấp với width 65. Xác minh đầu ra đối chiếu với văn bản usage dự kiến và bổ sung coverage cho thấy các tùy chọn có dấu gạch nối vẫn nguyên vẹn ở ranh giới dòng, trong khi việc ngắt dòng vẫn tuân theo độ rộng đã cấu hình.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.argumentwith custommetavarcontaining 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.
- Ngôn ngữ chính
- Python
- Star
- 17.8k
- Fork
- 3.3k
- Merge trung bình
- 3 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pallets/click
-
`show_envvar=True` Drops Environment Variable from Error Messages When Using `auto_envvar_prefix`Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
More private utilities that need to be marked and public api deprecatedCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởtyping
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
pallets/click#3847 · 9 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Automatically append ellipsis (`...`) to metavars when `multiple=True` in optionsCó thể đã có người làm @SparshGarg999 đã nhận 89 ngày trước. Đang mởhelp output
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
pallets/click#3652 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add glossary of terms to click reference docsCó thể đã có người làm @rohitbarhate111-commits đã nhận 55 ngày trước. Đang mởdocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
pallets/click#3077 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pallets/click
Issue tương tự
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
gke-labs/kube-agents#5671 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs(auth): Method B step 4 should tell users to tick "Use this client for an AI-powered agent"Đang mởdocumentation next-release v0.9.6
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
khuisman/mcp-gee-sweet#1446 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
In-box secret files written before their chmod: lc-creds, stacks tee, and the workspace tokenĐang mởmodel:sonnet runtime:claude security size:S
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
FootprintAI/Containarium#3671 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
HolidayBase: reassigning `language` does not re-initialize translations or re-populate holidaysCó thể đã có người làm @shikhabhadoria đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
vacanza/holidays#4116 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug CLI exec
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày