import { type SpawnOptions as nodeSpawnOptions } from "node:child_process"; /** Options controlling the markdown generated by {@link insertHelp}. */ export type InsertHelpOptions = { /** Include each command's flags beneath it. Defaults to true. */ flags?: boolean; }; /** * Opt in to recording top-level command invocations in the user's local state * directory. Positional argument values are never included in the log. */ export declare function logCommandUsage(): void; /** * Register a markdown file to receive an auto-generated command reference. * * On the next {@link Register} call, the command list (and each command's * flags) is rendered between `` and `` * markers in the file. A relative `path` resolves against the running script's * directory; an absolute path is used as-is. If the file is missing, nothing is * written; if its markers are missing, they are appended. Set `options.flags` * to false to generate only the visible command list. */ export declare function insertHelp(path: string, options?: InsertHelpOptions): void; /** * A single command-line flag definition. The type of {@link Flag.initial} * determines both the parsed value type and how the flag renders in help. */ export type Flag = { /** Default value; its type (number, string, boolean, or Date) is the flag type. */ initial: number | string | boolean | Date; /** One-line description shown in `--help` output. */ description: string; /** Optional env var name used as a fallback when the flag is not passed. */ env?: string; }; type Flags = Record; /** * Maps a set of {@link Flag} definitions to the runtime values passed to a * command's `run` — each flag becomes a property typed by its `initial` value * (number, string, boolean, or Date). */ export type FlagValues = { [P in keyof T]: T[P]["initial"] extends number ? number : T[P]["initial"] extends string ? string : T[P]["initial"] extends boolean ? boolean : T[P]["initial"] extends Date ? Date : never; }; /** * A command definition passed to {@link Command}. `F` captures the flag shape * so `run` receives strongly-typed flag values. */ export type TakeCommand = { /** Command name; whitespace creates automatic groups, e.g. `"db migrate"`. */ name: string; /** @deprecated Legacy internal field; Register no longer populates it. */ names?: string[]; /** One-line description shown in help listings. */ description: string; /** Optional long-form help shown under this command's own `--help`. */ help?: string; /** * When true, the command is omitted from help listings and from the * {@link insertHelp} markdown, but stays fully runnable and still shows its * own help via an explicit ` --help`. Use for internal or maintenance * commands you don't want to advertise. */ hidden?: boolean; /** Flag definitions for this command; use `{}` for none. */ flags: F; /** Handler run when the command is invoked, given parsed flags and args. */ run: (input: CommandInput) => void | Promise; }; /** * Identity helper that captures a flags object's literal type for reuse across * commands while keeping each flag's value type inferred. */ export declare function newFlags(flags: F): F; /** * A {@link TakeCommand} augmented by {@link Command} with type-only helper * fields. `flagValues` and `input` are always null at runtime — they exist so * their types can be referenced (e.g. `typeof cmd.input`). */ export type NewCommand = TakeCommand & { /** Type-only handle to the parsed flag values shape. Always null at runtime. */ flagValues: FlagValues; /** Type-only handle to the full `run` input shape. Always null at runtime. */ input: CommandInput; /** The flags' initial/default values, keyed by flag name. */ flagsInitial: FlagValues; }; /** Options for a command group. Groups organize commands but do not run. */ export type GroupOptions = { /** Group name. Whitespace-separated names create nested groups. */ name: string; /** One-line description shown in help listings. */ description?: string; /** Hide this group and its descendants from generated help. */ hidden?: boolean; }; /** A command or group accepted by {@link Register} and nested in a group. */ export type Registrable = NewCommand | NewGroup; /** A {@link GroupOptions} augmented by {@link Group} with its child entries. */ export type NewGroup = GroupOptions & { /** Internal discriminator added by {@link Group}. */ readonly kind: "group"; /** Commands and nested groups belonging to this group. */ readonly children: [Registrable, ...Registrable[]]; }; /** The argument object passed to a command's `run` function. */ export type CommandInput = { /** Parsed flag values, typed from the command's flag definitions. */ flags: FlagValues; /** Positional arguments remaining after flags are parsed. */ args: string[]; /** Invoke another command in the same CLI by name, e.g. `await cmd("build")`. */ cmd: (...args: string[]) => Promise; /** The resolved name of the running command. */ cmdName: string; /** Print this command's help (with an optional error message) and exit. */ help: (msg?: string) => void; }; /** * Abort a command's `run` with a help/usage error. The thrown string is caught * by the runner and shown as that command's help error message. */ export declare function help(str: string): void; /** * Stdio disposition for a single stream, in Deno.Command style. Lowered onto * node's stdio: "piped" → "pipe" (capturable by exec/run), "inherit" → the * parent's stream, "null" → "ignore". */ export type Stdio = "inherit" | "piped" | "null"; /** * Options for {@link spawn}, {@link exec}, and {@link run}. Extends node's * child_process `SpawnOptions`, adding a required `program` plus Deno-style * `stdin`/`stdout`/`stderr` dispositions (see {@link Stdio}). */ export type SpawnOptions = { /** The program/executable to run. */ program: string; /** Arguments passed to the program. */ args?: string[]; /** Disposition for the child's stdin (see {@link Stdio}). */ stdin?: Stdio; /** Disposition for the child's stdout (see {@link Stdio}). */ stdout?: Stdio; /** Disposition for the child's stderr (see {@link Stdio}). */ stderr?: Stdio; } & nodeSpawnOptions; /** * Run a program to completion. Resolves when the child exits with code 0, and * rejects with the non-zero exit code otherwise. Control output capture via the * `stdin`/`stdout`/`stderr` options (see {@link Stdio}). */ export declare function spawn(options: SpawnOptions): Promise; /** The outcome of a finished child process from {@link run} or {@link exec}. */ export type RunResult = { /** Process exit code (or 1 if it failed to start). */ code: number; /** Captured standard output (empty unless stdout was piped). */ stdout: string; /** Captured standard error (empty unless stderr was piped). */ stderr: string; /** Captured stdout and stderr interleaved in arrival order. */ combined: string; /** Spawn error message, if the process failed to start. */ error?: string; /** True when `code` is 0. */ success: boolean; }; /** Handle to a running child process returned by {@link exec}. */ export type ExecResult = { /** OS process id (0 if the process failed to start). */ pid: number; /** Spawn error message, if the process failed to start. */ error?: string; /** Await the process and resolve with its {@link RunResult}. */ wait: () => Promise; /** Send a signal to the process to terminate it. */ kill: (signal: number) => void; }; /** * Start a program and return an {@link ExecResult} handle immediately, exposing * its `pid`, a `kill` method, and `wait()` for the final {@link RunResult}. * Output is captured by default; use for long-running or concurrent processes. */ export declare function exec(options: SpawnOptions): ExecResult; /** * Run a program to completion and resolve with its {@link RunResult}. Unlike * {@link spawn}, a non-zero exit is reported in `result.code` rather than * thrown. Shorthand for `exec(options).wait()`. */ export declare function run(options: SpawnOptions): Promise; /** * Run a bash script with inherited stdio, e.g. `await $("ls -la | wc -l")`. * Rejects if the script exits non-zero. */ export declare const $: (script: string) => Promise; /** * Start a timer and return a `stop` function that yields the elapsed time as a * human-readable string (e.g. `"1.50sec"`). The returned function also * stringifies to that value, so it drops straight into a template literal: * `const t = timer(); ...; console.log(\`done in ${t}\`)`. */ export declare const timer: () => () => string; /** * Build the CLI from {@link Command} and {@link Group} definitions and run the * command named by `process.argv`. Loads a local `.env`, validates and * normalizes the command tree, generates `--help`, updates any * {@link insertHelp} target, then dispatches. Exits the process on help, * validation errors, or a command failure. */ export declare function Register(...registrables: Registrable[]): Promise; /** * Define a single CLI command. Wraps a {@link TakeCommand} and returns a * {@link NewCommand} with inferred flag-value types, ready to pass to * {@link Register}. */ export declare function Command(command: TakeCommand): NewCommand; /** * Define a CLI command group. A string is shorthand for `{ name: string }`; * commands and further groups are supplied as the remaining arguments. */ export declare function Group(options: string | GroupOptions, ...children: [Registrable, ...Registrable[]]): NewGroup; export {};