Help
Add help output to every command.
Usage
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 helphelp() owns the recursive --help and -h flag. It also shows help when the selected command has no Command Action. --help is an eager handler: it wins over every non-eager flag handler, such as deploy --preview --help, and between --help and --version the flag given first wins. The fallback runs as a noAction hook, only when no flag handler took over, so my-cli --version still prints the version on an action-less root. Subcommands are listed from their defineCommand() metadata without running their recipes, so a command whose recipe throws still appears.
A flag that takes a value shows its type after its spellings, such as -p, --port <number>. Boolean flags show none. Choices, defaults, and env variables follow the description. A label too wide for its column widens the column, so descriptions stay aligned.
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 = await 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 and resolves to the help text. The renderer and @crustjs/style load on the first call, so a CLI pays for them only when it prints help. path is the command path shown in the output and defaults to [meta.name].