Overview
The Man Page generator creates a Unix manual page (man page) from the CLI documentation. It extracts command-line options and environment variables from thecli.md file and formats them according to the mdoc specification.
The output follows the mdoc.7 formatting specification used by BSD man pages.
Metadata
Generator identifier
Generator version
Requires metadata generator output as input
Configuration
Output filename for the man page (section 1 for user commands)
Slug of the heading that contains CLI options
Slug of the heading that contains environment variables
Path to the man page template file
Output directory path for the generated man page
Output Format
The generator produces:- Man page file:
node.1(or custom filename) - Format: mdoc format with sections for options and environment variables
- Sections:
__OPTIONS__: Command-line flags and arguments__ENVIRONMENT__: Environment variable documentation
Usage
Dependency Chain
- ast - Parses Markdown to AST
- metadata - Extracts API metadata
- man-page - Converts CLI docs to man page format
Implementation Details
The generator:- Filters entries to only
cliAPI documentation - Locates section headings by configured slugs
- Extracts depth-3 headings between section boundaries
- Converts options to mdoc format using
convertOptionToMandoc - Converts environment variables using
convertEnvVarToMandoc - Fills template placeholders with generated content
Section Extraction
TheextractMandoc function:
- Takes a slice of components between section boundaries
- Filters for depth-3 headings (individual options/variables)
- Maps each to mdoc format using converter functions
- Joins results into a single string
Template Replacement
The template uses these placeholders:__OPTIONS__: Replaced with formatted CLI options__ENVIRONMENT__: Replaced with formatted environment variables
src/generators/man-page/