Skip to content

API Reference

clibuilder has a small surface. Everything below is a named export of the package root, unless its row names a subpath:

import { cli, command, parseArgv, t } from 'clibuilder'
import { testCommand } from 'clibuilder/testing'
Export Purpose
cli() Create the CLI builder — the entry point of every application
command() Identity helper that types a standalone command object
testCommand() Run a command in-process and capture its result and messages, from clibuilder/testing (the root export is removed in v12)
config() The config extension, passed to .use(), from clibuilder/config
defineKey() / defineCollectionKey() Create typed plugin registry keys
parseArgv() The raw argv tokenizer, exported for reuse
enableCompileCache() Opt into Node’s V8 compile cache, from clibuilder/compile-cache
clibuilder/axi Truncation, counts, the empty state and the home header, from the clibuilder/axi subpath
isCliError() Whether a caught value is a CliError
Export Purpose
t The type descriptors for arguments and options (replaces z)
result, document, empty Mark what run() returns as a result, a document or an empty state
exitCodes The codes the cli exits with — success, error, usage
CliError Thrown from run() to fail the cli with a message and an exit code
Export Purpose
cli.Options Options accepted by cli()
cli.UsageError One usage error found while parsing, as passed to onUsageError
cli.UsageErrorHandler The signature of onUsageError, on cli() options and on a command
cli.UsageErrorContext The second argument of onUsageError: command, ui, format, exitCode
cli.Format 'toon' | 'json' | 'text'
cli.Command The shape of a command
cli.Command.Argument A positional argument declaration
cli.Command.Options The options record declaration
Answer What result(), document() and empty() return
Renderer (value) => string, renders a result for one format
ConfigExtension The type of what config() returns
UI The object on this.ui inside run()
DisplayLevel 'none' | 'info' | 'debug' | 'trace'
Extension A function passed to .use() (11.5.0)
ExtensionContext What an extension receives (11.5.0)
PluginActivationContext What a plugin’s activate() receives
mockExtensionContext() A context for testing an extension passed to .use(), from clibuilder/testing
mockPluginContext() A context for testing a deprecated plugin’s activate(), from clibuilder/testing
Registry Read-only values and contributions available as this.registry in commands

Most of the command types live under the cli namespace rather than at the top level, so you rarely import them directly — command() infers them for you.