Skip to content

Help ​

--help pages are generated from your definitions:

sh
$ app sync --help
Sync files

Usage:
  app sync [flags] <files>
  app sync <command>

Commands:
  repeat  Sync files repeatedly

Arguments:
  <files>  Path to the files (required)

Flags:
  -h, --help       Show help
  --mode <string>  Sync mode (choices: fast, safe; default: safe)
  -r, --repeat     Repeat the operation
  -v, --verbose    Increase verbosity (env: VERBOSE)
  --version        Show version

Pages are rendered by a HelpTemplate. To customise them, pass an instance as help to jinju(), either with options or by extending the class.

Options ​

ts
jinju
({
commands
,
help
: new
HelpTemplate
({
sortFlags
: false,
showHidden
: true }) });
OptionDefaultDescription
sortFlagstrueSort flags by long name. With false, they keep definition order.
showHiddenfalseInclude hidden commands and flags.

Extending the template ​

Override any method to change part of the page, and call super to build on the default:

ts
class 
MyHelp
extends
HelpTemplate
{
override
formatFlag
(
flag
: HelpFlag) {
const [
label
,
description
] = super.
formatFlag
(
flag
);
return [
label
,
flag
.
source
=== 'builtin' ? `${
description
} (built-in)` :
description
] as
const
;
} override
sections
(
data
: HelpData) {
return [`${
data
.
program
.
name
} v${
data
.
program
.
version
}`, ...super.
sections
(
data
)];
} }
jinju
({
version
: '1.0.0',
help
: new
MyHelp
({
sortFlags
: false }),
commands
});
MethodDefault
render(data)Joins sections(data) with blank lines and adds a trailing newline. Override it to replace the layout entirely
sections(data)[description, usage, commands, args, flags], with empty sections left out
formatUsage, formatCommands, formatArgs, formatFlagsEach renders one section from data
commands(data), flags(data)Choose what to list: hidden entries are left out unless showHidden, and flags are sorted unless sortFlags: false
formatCommand, formatArg, formatFlagOne [left, right] table row each
formatTags, formatValue, formatPath (required; default: 3), default values, <project> deploy
formatTable(rows), formatSection(title, lines)Layout primitives

The text render returns is printed as-is, so it should end with a newline.

Help data ​

HelpData holds the building blocks of a page, and the template decides what to use and how. It makes no layout decisions: nothing is filtered or sorted.

FieldContents
programname, version, description
pathThe command path as { name, dynamic } parts. formatPath(path) gives <project> deploy
description, aliases, runnableThis level's description, its command's aliases, and whether it has a command to run
usageUsage lines, e.g. app <project> deploy [flags] [<env>]
commandsEach subcommand: name, label, description, aliases, hidden, dynamic, full path, runnable, group (has subcommands)
argsEach arg in order: name, label (<env>), usage ([<env>]), source (command or scope), segment
flagsEach flag in definition order, hidden ones included: key, name, alias, kind (flag or switch), env, source (command, scope or builtin), hidden, label (-n, --dry-run <string>)

Args and flags also carry description, type, required, multiple, hasDefault, the raw default, choices, and options. options is everything passed to the creator, including min, max, integer, exists and the options of custom parsers.

See the Help API for every type.