Skip to content

Fix mid-word truncation of Go CLI command descriptions - #265

Merged
rich-iannone merged 1 commit into
posit-dev:mainfrom
jeroenjanssens:fix-go-cli-short-help-truncation
Jul 17, 2026
Merged

Fix mid-word truncation of Go CLI command descriptions#265
rich-iannone merged 1 commit into
posit-dev:mainfrom
jeroenjanssens:fix-go-cli-short-help-truncation

Conversation

@jeroenjanssens

Copy link
Copy Markdown
Contributor

Problem

On the CLI reference index page (/reference/cli/), a Go CLI's command summary was cut off mid-word with no ellipsis:

velocirepo tracks your open-source project's pulse across package registries, Gi

The summary (short_help) for Cobra commands was built with a hard description[:80] slice in _go_cli.py. Cobra's root and group --help output carries the full (Long) description, so slicing the first 80 characters cut it mid-word.

(Subcommands were unaffected — their summaries come from Cobra's concise "Available Commands" listing. The Click CLI path already handled this correctly via get_short_help_str(limit=150); the Go path just didn't match it.)

Fix

Introduce a _short_help() helper that prefers the first sentence and otherwise truncates on a word boundary with an ellipsis, using the same 150-char limit and ... placeholder as the Click path so both ecosystems read consistently.

Testing

  • Added TestShortHelp covering the empty, short, first-sentence, long-single-sentence (word-boundary + ellipsis), and within-limit cases.
  • All 60 tests/test_go_cli.py tests pass.
  • Verified end-to-end: rebuilding a Go project (velocirepo) now renders the summary truncated on a word boundary with ... instead of a mid-word cut.

The CLI reference index page showed each command's summary via `short_help`,
which for Cobra commands was a hard `description[:80]` slice. Cobra's root and
group `--help` output carries the full (Long) description, so the summary was
cut mid-word with no ellipsis, e.g.:

    velocirepo tracks your open-source project's pulse across package registries, Gi

Introduce a `_short_help()` helper that prefers the first sentence and
otherwise truncates on a word boundary with an ellipsis, using the same 150-char
limit and "..." placeholder as the Click path's `get_short_help_str(limit=150)`
so both ecosystems read consistently.

Add unit tests covering the empty, short, first-sentence, long-single-sentence
(word-boundary + ellipsis), and within-limit cases.

@rich-iannone rich-iannone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@rich-iannone
rich-iannone merged commit 81ae5a7 into posit-dev:main Jul 17, 2026
8 checks passed
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.

2 participants