Skip to content

Display command aliases in generated man-pages#891

Merged
rauhul merged 1 commit into
apple:mainfrom
qflen:display-aliases-in-man-pages
Apr 22, 2026
Merged

Display command aliases in generated man-pages#891
rauhul merged 1 commit into
apple:mainfrom
qflen:display-aliases-in-man-pages

Conversation

@qflen
Copy link
Copy Markdown
Contributor

@qflen qflen commented Apr 21, 2026

Resolves #851 (and partially addresses the umbrella #849).

Subcommand aliases already flow through CommandInfoV0.aliases and surface in --help and dump-help output, but the generate-manual tool never consumed them.

Changes

  • Tools/generate-manual/Extensions/ArgumentParser+MDoc.swift: new manualPageSubcommandLabel helper that returns commandName alone, or "commandName, alias1, alias2" when aliases exist. Mirrors the format used by HelpGenerator.
  • Tools/generate-manual/DSL/SinglePageDescription.swift: use the helper when rendering each subcommand list item.
  • Tools/generate-manual/DSL/Name.swift: emit one .Nm macro per alias in the NAME section. This is the canonical BSD mdoc convention (see ls(1), which lists ls, dir in NAME).
  • Regenerated the two testMath*Manual snapshots. The other ten snapshots are unchanged because the guard in manualPageSubcommandLabel short-circuits for commands without aliases, so output for alias-less commands is byte-identical.

Example output

Single-page (Math example, subcommand list):

.It Em "multiply, mul"
Print the product of the values.
...
.It Em "average, avg"
Print the average of the values.

Multi-page (NAME section on each subcommand page):

.Sh NAME
.Nm "math multiply"
.Nm mul
.Nd "Print the product of the values."

Scope decisions

  • SeeAlso.swift: left alone. It cross-references other man-pages, and aliases do not generate their own pages.
  • Synopsis.swift: left alone. The bare .Nm auto-resolves to the first .Nm in the document, which remains the primary name.
  • MultiPageDescription.swift: does not iterate subcommands, so no change needed.

Test plan

  • swift test --filter GenerateManualTests passes (12/12)
  • Verified the existing Math example (which already declares mul and avg aliases via PR Add aliases support for sub commands #627) now renders them in both single-page and multi-page output
  • Confirmed non-aliased commands produce byte-identical output (other 10 snapshots unchanged)

@rauhul
Copy link
Copy Markdown
Collaborator

rauhul commented Apr 21, 2026

Thanks for the contribution, do you have another reference for this:

Tools/generate-manual/DSL/Name.swift: emit one .Nm macro per alias in the NAME section. This is the canonical BSD mdoc convention (see ls(1), which lists ls, dir in NAME).

dir isn't a command on macOS and therefore isn't present in the manual.

@qflen
Copy link
Copy Markdown
Contributor Author

qflen commented Apr 21, 2026

You're right, ls(1) was a bad example on my part. Better evidence, all from macOS:

grep(1):

NAME
     grep, egrep, fgrep, rgrep, bzgrep, bzegrep, bzfgrep, zgrep, zegrep,
     zfgrep -- file pattern searcher

test(1):

NAME
     test, [ -- condition evaluation utility

And the convention is documented in mdoc(7):

Nm [name]: The name of the manual page, or (particularly in section 1, 6, and 8 pages) of an additional command or feature documented in the manual page.

That is, in executable sections (1, 6, 8), repeated Nm macros are the standard way to list aliased names on one page. If you'd prefer a different format, or would rather keep aliases only in the single-page subcommand list, happy to change it.

@qflen qflen force-pushed the display-aliases-in-man-pages branch from 21ad6a5 to 3b19f7b Compare April 21, 2026 19:37
Subcommand aliases already surface in --help and dump-help, but the
generate-manual tool ignored CommandInfoV0.aliases. Single-page output
now lists aliases inline with the subcommand name (e.g. "multiply, mul"),
matching the --help format. Multi-page output lists aliases as
comma-separated .Nm entries in the NAME section, following the BSD mdoc
convention (see ls(1)).

Resolves apple#851.
@qflen qflen force-pushed the display-aliases-in-man-pages branch from 3b19f7b to d82d90d Compare April 21, 2026 19:38
@rauhul rauhul merged commit 63958cf into apple:main Apr 22, 2026
35 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.

Command aliases should appear in generated man-pages

2 participants