Crust logoCrust

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/man

The 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.1

man() 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.

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.1

Prop

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:

package.json
{
  "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.1

Here 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 ")); // => true

Prop

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 (Files renders 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, so C:\tmp or \fB render literally rather than as roff.
  • Without date, .Dd uses SOURCE_DATE_EPOCH in UTC when set, then the current local date, in the English Month D, YYYY form 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.

On this page