Skip to content

fix: render man page flags as tagged paragraphs - #2522

Open
seflue wants to merge 1 commit into
spf13:mainfrom
seflue:fix/man-flag-layout
Open

seflue wants to merge 1 commit into
spf13:mainfrom
seflue:fix/man-flag-layout

Conversation

@seflue

@seflue seflue commented Oct 5, 2026

Copy link
Copy Markdown

Closes #2520

manPrintFlags now writes the flag usage as a go-md2man definition list (: usage), which renders as .TP. gh uses the same form in its copy of the generator.

A definition list alone isn't enough, because go-md2man still reads the usage as Markdown. It turns a usage line starting with - , * , + or 1. into a list and indents all following flags by 2 instead of 7. A blank line in the usage ends the definition, and the next paragraph loses its indent. The fix escapes these markers at the start of each line and indents the following lines by four spaces.

The escaping also fixes an existing bug. Until now, a usage line starting with # turned into a section heading, and all following flags ended up under it.

TestGenManFlagsAsTaggedParagraphs covers these cases. TestManPrintFlagsHidesShortDeprecated now expects the definition list instead of the tab-indented line.

I built docker, hugo, restic, caddy and helm against this branch and generated their man pages. Every flag now renders as .TP. The text of the pages is unchanged, only the flag layout differs.

restic's restic-backup.1, before and after (MANWIDTH=80):

     --exclude-caches[=false]      excludes cache directories that  are  marked
     with  a  CACHEDIR.TAG file. See https://bford.info/cachedir/ for the Cache
     Directory Tagging Standard
     --exclude-caches[=false]
            excludes cache directories that  are  marked  with  a  CACHEDIR.TAG
            file. See https://bford.info/cachedir/ for the Cache Directory Tag‐
            ging Standard

Fixes spf13#2520

Since go-md2man v2 (cobra v0.0.6), the tab-indented usage line after
each flag is joined with the flag into one paragraph, so man pages show
the description on the same line as the flag.

Write the usage as a go-md2man definition list instead, which renders
as .TP. Escape list and heading markers at the start of usage lines and
indent the following lines, so multi-line usages stay inside the
definition.
@CLAassistant

CLAassistant commented Oct 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the area/docs-generation Generation of docs via Cobra label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docs-generation Generation of docs via Cobra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated man pages put flag and description on one line

2 participants