import { Command } from "./command.js"; import type { Deps } from "./deps.js"; import type { AnyMiddleware, Middleware } from "./middleware.js"; /** * What a `Cli` dispatches to: a command, or a group that dispatches again. * `Command` satisfies it as it is, which is what lets the two nest freely. */ interface Node { /** What it does, beside the name it registered under in the parent's help. */ summary(): string; exec(argv: string[], deps: D, outer: AnyMiddleware[], path: string): unknown; } /** * `D` is what `run` is handed and what the actions start from; `C` is what the * middleware has made of it by the time an action runs. Declaring a cli * therefore takes no dependencies at all, which is what makes the declaration * itself testable: build it once at module scope, run it with fakes. */ export declare class Cli implements Node { readonly name: string; private cmds; private middleware; private _description; private _fallback; constructor(name: string); /** Only shown when this is a group, on its line in the parent's help. */ description(description: string): this; /** Wraps every command's action. Call it before any `command()`. */ use(middleware: Middleware): Cli; command(name: string): Command; /** * A subcommand that is itself a set of subcommands: `skills add`, `skills * update`. The group is a `Cli` too, so it groups, takes middleware and * prints help exactly the way the root does; only its name is longer. */ group(name: string): Cli; /** * The subcommand that runs when the first argument names none of the * others, or there is none: `scry` runs `scry check`, and so do * `scry ./app` and `scry --since main`, while `scry add` still adds. It * gets the whole argument list. `--help` still prints this cli's help. */ fallback(name: string): this; /** * Mounts another cli's commands under `name`. The mounted cli is built * standalone, as its own program; here it becomes a group, and help names * every command by the path it was reached through, not the name the * mounted cli was built with. */ mount(name: string, sub: Cli): this; /** * The program's own dependencies; `log` and `ps` are filled in with the real * ones when left out, and `argv` with the process's own arguments, so a bin * only names what is its own. A test that wants fakes passes them. */ run(deps: Omit & Partial, argv?: string[]): unknown; /** * Dispatch, with whatever middleware the levels above contribute. Errors are * left to propagate: only the root's `run` ends the process, so a group * nested three deep still fails once, at the top. `path` is the spelling * that reached this cli, which only the caller knows: a mounted cli is * named one way on its own and another under the program that mounts it. */ exec(argv: string[], deps: D, outer?: AnyMiddleware[], path?: string): unknown; summary(): string; private fail; private help; } export declare function cli(name: string): Cli; export {};