cli/help.ts

Schema-driven CLI help generator.

Generalized from the identical pattern in tx and zzz. Consumers configure once with create_help and get back generate_main_help, generate_command_help, and get_help_text.

Declarations
#

7 declarations

view source

CommandMeta
#

cli/help.ts view source

CommandMeta<TCategory>

Command metadata for help generation.

generics

TCategory

constraint string
default string

schema

type z.ZodType

summary

type string

usage

type string

category

type TCategory

create_help
#

cli/help.ts view source

<TCategory extends string>(options: HelpOptions<TCategory>): HelpGenerator

Create a help generator configured for an application.

options

help configuration

type HelpOptions<TCategory>

returns

HelpGenerator

help generator with generate_main_help, generate_command_help, and get_help_text

format_arg_name
#

cli/help.ts view source

(prop: ZodSchemaProperty): string

Format argument name with short aliases for display.

Only single-char aliases are shown (e.g., -h, --help). Flags use snake_case (e.g., --env_file, --detect_only).

prop

schema property

type ZodSchemaProperty

returns

string

formatted name string

HelpCategory
#

cli/help.ts view source

HelpCategory<TCategory>

Category configuration for help display.

generics

TCategory

constraint string
default string

key

type TCategory

title

type string

HelpGenerator
#

cli/help.ts view source

HelpGenerator

Help generator returned by create_help.

generate_main_help

Generate main help text with all commands grouped by category.

type () => string

generate_command_help

Generate help text for a specific command.

type (command: string, meta: CommandMeta) => string

get_help_text

Get help text for a command or main help.

type (command?: string, subcommand?: string) => string

HelpOptions
#

cli/help.ts view source

HelpOptions<TCategory>

Configuration for create_help.

generics

TCategory

constraint string
default string

name

Application name (e.g., "tx", "zzz").

type string

version

Application version string.

type string

description

Short description for the main help header.

type string

commands

Command registry keyed by command path (e.g., "apply", "daemon start").

type Record<string, CommandMeta<TCategory>>

categories

Category display order for main help.

type Array<HelpCategory<TCategory>>

examples

Example commands for main help.

type Array<string>

global_args_schema

Zod schema for global arguments (shown in all help output).

type z.ZodType

use_colors

Whether to use ANSI colors in output. Defaults to true.

type boolean

to_max_length
#

cli/help.ts view source

<T>(items: T[], to_string: (item: T) => string): number

Get maximum length from array.

items

array of items

type T[]

to_string

function to convert item to string for length measurement

type (item: T) => string

returns

number

maximum string length

Depends on
#