Skip to content

Help message

Four standalone functions, plus the two methods attached to the CLI and its subcommands. They all take the same PrintHelpOptions.

Functions

generateCliHelpMessage

(cliDefinition: Cli, options?: PrintHelpOptions) => string

generateSubcommandHelpMessage

(commandDefinition: Subcommand, options?: PrintHelpOptions, cliName?: string) => string

The usage line uses cliName. Pass it so the message reads listy add-items ... instead of just add-items ....

printCliHelp

(cliDefinition: Cli, options?: PrintHelpOptions) => void

printSubcommandHelp

(commandDefinition: Subcommand, options?: PrintHelpOptions, cliName?: string) => void

The print pair writes to the console. The generate pair returns the string.

Inside a handler, prefer the attached methods, which already know the CLI name. See Cli.

PrintHelpOptions

Option Type Default Description
style HelpMessageStyle helpMessageStyles.default Colors for each part of the message.
kebabCaseArgumentName boolean true Show argument names in kebab-case. Does not affect options.
markdownRenderer "terminal" | "html" "terminal" How descriptionMarkdown is rendered.
indentBeforeName number 2 Spaces before an option, argument, or command name.
indentAfterName number 4 Spaces between the name column and the description column.
indentBeforePlaceholder number 1 Spaces before the placeholder.
newLineIndent number 0 Indent for wrapped description lines and examples.
emptyLines number 0 Empty lines between entries.
emptyLinesBeforeTitle number 1 Empty lines before a section title.
emptyLinesAfterTitle number 0 Empty lines after a section title.
exampleKeyword string "Example:" Label before an example.
optionalKeyword string "(optional)" Marker for optional entries.
defaultKeyword string "(default: {{ value }})" Marker for defaults. {{ value }} is replaced.
usageTitle string "USAGE" Section title.
descriptionTitle string "DESCRIPTION" Section title.
commandsTitle string "COMMANDS" Section title.
optionsTitle string "OPTIONS" Section title.
argumentsTitle string "ARGUMENTS" Section title.
exampleTitle string "EXAMPLE" Section title.

helpMessageStyles

Ready-made styles: default, dracula, nord, solarizedDark, gruvboxDark, monokai, oneDark, catppuccin, noColors, and html.

import { helpMessageStyles } from "@staticbolt/args-parser";
cli.generateCliHelpMessage({ style: helpMessageStyles.nord });

HelpMessageStyle

new HelpMessageStyle(style, baseStyle?)

Each part is a function that takes text and returns styled text, which is exactly the shape of a chalk color. Anything you leave out falls back to baseStyle, or to plain text when there is no base.

Part Applies to
title Section titles.
description Descriptions.
default The default marker.
optional The optional marker.
exampleTitle The example label.
example Example text.
command Subcommand names.
option Option flags.
argument Argument names.
placeholder Placeholders.
punctuation Brackets, commas, and the like.
import { HelpMessageStyle, helpMessageStyles } from "@staticbolt/args-parser";
import chalk from "chalk";
const myStyle = new HelpMessageStyle({ title: chalk.bold.magenta }, helpMessageStyles.default);

See Help messages for the HTML output and other usage.