import { z } from 'zod'; /** * CLI arguments container. * Positional arguments stored in `_`, named flags/options as string keys. * Produced by `argv_parse` or external parsers (mri, minimist, etc.). */ export interface Args { _?: Array; [key: string]: ArgValue; } /** * Parsed CLI arguments with guaranteed positionals array. * Returned by `argv_parse` which always initializes `_`. */ export interface ParsedArgs extends Args { _: Array; } /** * Value types supported in CLI arguments. */ export type ArgValue = string | number | boolean | undefined | Array; /** * Schema description for help text generation. * Not used by `args_parse`/`args_serialize` directly - provided for consumers * building CLI help output. */ export interface ArgSchema { type: string; default: ArgValue; description: string; } /** * Result of alias extraction from a schema. * Includes canonical keys for downstream conflict detection. */ export interface ArgsAliasesResult { aliases: Map; canonical_keys: Set; } /** * Validates a zod schema for CLI arg usage. * * Checks for: * - Alias conflicts with canonical keys * - Duplicate aliases across different keys * * Results are cached per schema (WeakMap). Safe to call multiple times. * * @param schema - zod object schema with optional alias metadata * @returns validation result with success flag and optional error */ export declare const args_validate_schema: (schema: z.ZodType) => { success: true; } | { success: false; error: z.ZodError; }; /** * Validates parsed CLI args against a zod schema. * * Handles CLI-specific concerns before validation: * 1. Validates schema (cached) - returns error if alias conflicts exist * 2. Expands aliases defined in schema `.meta({aliases: ['v']})` * 3. Strips alias keys (required for strictObject schemas) * 4. Validates with zod * 5. After validation, syncs `no-` prefixed boolean flags with their base keys * * Schema analysis is cached per schema (WeakMap) for performance. * * @param unparsed_args - args object from CLI parser (mri, minimist, etc.) * @param schema - zod object schema with optional alias metadata * @returns `z.ZodSafeParseResult` with expanded/synced data on success */ export declare const args_parse: = Args>(unparsed_args: Args, schema: z.ZodType) => z.ZodSafeParseResult; /** * Serializes Args to CLI string array for subprocess forwarding. * * Handles CLI conventions: * - Positionals first, then flags * - Single-char keys get single dash, multi-char get double dash * - Boolean `true` becomes bare flag, `false` is skipped * - `undefined` values are skipped * - `no-` prefixed keys skipped when base key is truthy (avoid contradiction) * - When schema provided, extracts aliases and prefers shortest form * * Schema analysis is cached per schema (WeakMap) for performance. * * @param schema - optional zod schema to extract aliases for short form preference */ export declare const args_serialize: (args: Args, schema?: z.ZodType) => Array; /** * Extracts alias mappings and canonical keys from a zod schema's metadata. * * Useful for consumers building custom tooling (help generators, conflict detection, etc.). * Results are cached per schema (WeakMap). * * Note: Returns copies of the cached data to prevent mutation of internal cache. * * @param schema - zod object schema with optional `.meta({aliases})` on fields */ export declare const args_extract_aliases: (schema: z.ZodType) => ArgsAliasesResult; /** * Parses raw CLI argv array into an Args object. * * A lightweight, dependency-free alternative to mri/minimist with compatible behavior. * * Features: * - `--flag` → `{flag: true}` * - `--flag value` → `{flag: 'value'}` or `{flag: 123}` (numeric coercion) * - `--flag=value` → equals syntax * - `--flag=` → `{flag: ''}` (empty string, differs from mri which returns true) * - `-f` → `{f: true}` (short flag) * - `-f value` → `{f: 'value'}` * - `-abc` → `{a: true, b: true, c: true}` (combined short flags) * - `-abc value` → `{a: true, b: true, c: 'value'}` (last flag gets value) * - `--no-flag` → `{flag: false}` (negation prefix) * - `--` → stops flag parsing, rest become positionals * - Positionals collected in `_` array * - Repeated flags become arrays * * Intentional differences from mri: * - `--flag=` returns `''` (mri returns `true`) * - `--flag= next` returns `{flag: '', _: ['next']}` (mri takes `next` as the value) * - `---flag` returns `{'-flag': true}` (mri strips all dashes) * - `['--flag', '']` preserves `''` (mri coerces to `0`) * - `--__proto__` works as a normal key (mri silently fails) * * The returned object uses `Object.create(null)` to prevent prototype pollution * and allow any key name including `__proto__` and `constructor`. * * @param argv - raw argument array (typically process.argv.slice(2)) * @returns parsed `Args` object with guaranteed `_` array (null prototype) */ export declare const argv_parse: (argv: Array) => ParsedArgs; //# sourceMappingURL=args.d.ts.map