cli/config.ts

Generic CLI configuration loader.

Manages CLI-specific configuration stored at ~/.{name}/config.json. Consumers keep their project-specific Zod schemas locally and use these generic load/save functions.

Declarations
#

4 declarations

view source

get_app_dir
#

cli/config.ts view source

(runtime: Pick<EnvDeps, "env_get">, name: string): string | null

Get the CLI config directory path (~/.{name}).

runtime

runtime with env_get capability

type Pick<EnvDeps, "env_get">

name

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

type string

returns

string | null

path to config directory, or null if $HOME is not set

get_config_path
#

cli/config.ts view source

(runtime: Pick<EnvDeps, "env_get">, name: string): string | null

Get the CLI config file path (~/.{name}/config.json).

runtime

runtime with env_get capability

type Pick<EnvDeps, "env_get">

name

application name

type string

returns

string | null

path to config.json, or null if $HOME is not set

load_config
#

cli/config.ts view source

<T>(runtime: FsReadDeps & LogDeps, path: string, schema: ZodType<T, unknown, $ZodTypeInternals<T, unknown>>): Promise<T | null>

Load CLI configuration from a JSON file with Zod schema validation.

runtime

runtime with file read capability

type FsReadDeps & LogDeps

path

path to the config JSON file

type string

schema

Zod schema to validate against

type ZodType<T, unknown, $ZodTypeInternals<T, unknown>>

returns

Promise<T | null>

parsed config, or null if file doesn't exist or is invalid

save_config
#

cli/config.ts view source

<T>(runtime: FsWriteDeps, path: string, dir: string, config: T): Promise<void>

Save CLI configuration to a JSON file.

Creates parent directories if they don't exist.

runtime

runtime with file write capability

path

path to the config JSON file

type string

dir

directory containing the config file (created if missing)

type string

config

configuration to save

type T

returns

Promise<void>

Imported by
#