Man
Generate mdoc(7) manual pages from Crust command definitions
@crustjs/man renders an mdoc(7) manual page from your command definitions: during crust build through the man() Extension, or from your own script.
Install
npm install -D @crustjs/manThe package has a peer dependency on @crustjs/core.
man(options?)
import { Crust } from "@crustjs/core";
import { man } from "@crustjs/man";
const app = new Crust("my-cli").extend(man());.crust/artifacts/man/my-cli.1man() only registers a build hook; it writes nothing at runtime. During crust build, the hook returns man/<name>.<section>, which the build writes, copies into the staged packages, and records as an artifact of crust:man.
- The page is named after the root command, which
crust buildrequires to match the installed command. - Pass
man({ section: 5 })to change the section and file name. man.idis the Extension identity, for section filtering.
Prop
Type
writeManPage(options)
import { writeManPage } from "@crustjs/man";
const root = await app.snapshot();
await writeManPage({ root, outfile: "man/my-cli.1" });
// Writes man/my-cli.1Prop
Type
writeManPage() renders a Command Snapshot, creates parent directories, and writes the page. Use it for a custom pipeline outside crust build, such as a package script:
{
"scripts": { "generate:man": "bun run scripts/generate-man.ts" },
"files": ["dist", "man"],
"man": ["./man/my-cli.1"]
}npm run generate:man
man -l man/my-cli.1
mandoc -T lint -W warning man/my-cli.1Here scripts/generate-man.ts imports your app and calls writeManPage() as above; npm's man field installs the page.
renderManPageMdoc(options)
import { renderManPageMdoc } from "@crustjs/man";
const root = await app.snapshot();
const source = renderManPageMdoc({ root });
console.log(source.startsWith(".Dd ")); // => trueProp
Type
renderManPageMdoc() returns mdoc text without writing a file. It accepts a Command Snapshot, not a live definition.
Page contents
The page documents the root command: name, synopsis, description, SUBCOMMANDS (immediate visible children), OPTIONS, and ARGUMENTS.
- Root documentation sections follow as their own
.Sh, with uppercased titles (Filesrenders as.Sh FILES). Same-title sections merge at their first position. - Sections of visible subcommands are collected under
.Sh COMMANDS. - Descriptions, usage lines, and section bodies are plain text: backslashes and leading
.or'are escaped, soC:\tmpor\fBrender literally rather than as roff. - Without
date,.DdusesSOURCE_DATE_EPOCHin UTC when set, then the current local date, in the EnglishMonth D, YYYYform mdoc expects.
new Crust("my-cli", {
sections: [{ title: "FILES", body: "~/.config/my-cli.json", only: [man] }],
});Use only: [man] to include a section only in manual pages, or except: [man] to omit it there.