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.

view source

Declarations
#

7 declarations

CommandMeta
#

cli/help.ts view source

CommandMeta<TCategory> import type {CommandMeta} from '@fuzdev/fuz_app/cli/help.js';

Command metadata for help generation.

generics

CommandMeta<TCategory extends string = string>
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 import {create_help} from '@fuzdev/fuz_app/cli/help.js';

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

generics

create_help<TCategory extends string>
TCategory
constraint string

format_arg_name
#

cli/help.ts view source

(prop: ZodSchemaProperty): string import {format_arg_name} from '@fuzdev/fuz_app/cli/help.js';

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> import type {HelpCategory} from '@fuzdev/fuz_app/cli/help.js';

Category configuration for help display.

generics

HelpCategory<TCategory extends string = string>
TCategory
constraint string
default string

key

type TCategory

title

type string

HelpGenerator
#

cli/help.ts view source

HelpGenerator import type {HelpGenerator} from '@fuzdev/fuz_app/cli/help.js';

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> import type {HelpOptions} from '@fuzdev/fuz_app/cli/help.js';

Configuration for create_help.

generics

HelpOptions<TCategory extends string = string>
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 import {to_max_length} from '@fuzdev/fuz_app/cli/help.js';

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

generics

to_max_length<T>
T

Depends on
#