Crust logoCrust

Help

Add help output to every command.

Usage

cli.ts
import { Crust, defineCommand } from "@crustjs/core";
import { help } from "@crustjs/extensions";

const app = new Crust("my-cli", { description: "My CLI" })
	.extend(help())
	.add(
		defineCommand("deploy", { description: "Deploy the app" }, (command) =>
			command.action(() => {}),
		),
	)
	.action(() => {});

await app.execute();
$ my-cli --help
my-cli - My CLI

Usage:
  my-cli [options]

Commands:
  deploy     Deploy the app

Options:
  -h, --help                   Show help

help() owns the recursive --help and -h flag. It also shows help when the selected command has no Command Action.

Section consumer

const documentedApp = new Crust("my-cli", {
  sections: [{ title: "Example", body: "my-cli deploy", only: [help] }],
});

Use help as a section consumer to include or exclude sections from its output. Hidden commands remain routable but do not appear in command listings.

renderHelp

const text = renderHelp(await app.snapshot());
// => "my-cli - My CLI\n\nUsage:\n  my-cli [options] ..."

renderHelp(command, path?) renders a Command Snapshot without running the app. path defaults to the supplied snapshot's meta.name.

On this page