Skip to content

CliOutput

Formats CLI help and errors as text.

This module turns help documents, CLI errors, grouped errors, and version information into strings. It does not write those strings to the terminal itself. It includes the Formatter interface, the formatter service, a layer for custom formatters, and the default formatter with configurable color support.

4 exports Added in v4.0.0 Source

Constructors

Creates a default formatter with configurable options.

Signature

declare function defaultFormatter(options?: { colors?: boolean }): Formatter;

Layers

layer

Added in v4.0.0 Source

Creates a Layer that provides a custom Formatter implementation.

Signature

declare function layer(formatter: Formatter): Layer<never>;

Models

Formatter interface

Added in v4.0.0 Source

Defines the service interface for formatting CLI output including help, errors, and version info. This allows customization of output formatting, including color support.

Signature

interface Formatter {
  readonly formatCliError: (error: CliError) => string;
  readonly formatError: (error: CliError) => string;
  readonly formatErrors: (errors: readonly Array<CliError>) => string;
  readonly formatHelpDoc: (doc: HelpDoc) => string;
  readonly formatVersion: (name: string, version: string) => string;
}

Services

Formatter

Added in v4.0.0 Source

Service reference for the CLI output formatter. Provides a default implementation that can be overridden for custom formatting or testing.

Signature

declare const Formatter: Reference<Formatter>;