/** * mount-result-command — action-body helper for CLI-owned subcommands * that produce a `CommandResult`. * * Centralizes the per-subcommand boilerplate every result-producing * action body would otherwise repeat: * * - Run the supplied handler (sync or async). * - If `--json` was set, emit the result as JSON to stdout and bail * before Ink starts. Bypassing the renderer keeps `--json` * contract-faithful: machine consumers should never see ANSI * escapes or Ink's whitespace adjustments. * - Otherwise route the result through the renderer the dispatcher * wired into the context. * * Two shapes are exposed: * * - `mountResultCommand(cmd, handler)` — opts-only handler. Used by * `init`, `sessions list`, `plugin list`, `plugin sync`. * - `mountResultCommandWithArg(cmd, handler)` — single-positional-arg * handler. Used by `plugin add` / `plugin remove`. * * Phase 5 of the Layer 5 plan introduces this helper; Phase 6 routes * `clear` and `configure` through it (eliminating the last raw-ANSI * bypasses). */ import type { CliCommandsContext } from './shared.js'; import type { CommandResult } from '@opensip-cli/contracts'; import type { Command } from 'commander'; export type CommandHandler = (opts: TOpts) => CommandResult | Promise; export interface MountResultCommandOptions { readonly ctx: CliCommandsContext; /** * Pull the `--json` flag value out of the parsed Commander options. * The `--json` flag itself is the caller's responsibility — they * declare it on their `Command` before mounting. The mount helper * doesn't add the flag so each subcommand can keep its own help text. */ readonly jsonFlag?: (opts: TOpts) => boolean | undefined; } /** * Mount a result-producing handler as the action body of `cmd`. * The handler returns a `CommandResult`; `mountResultCommand` handles * the `--json` short-circuit and the Ink render dispatch. */ export declare function mountResultCommand(cmd: Command, handler: CommandHandler, opts: MountResultCommandOptions): void; export type CommandHandlerWithArg = (arg: TArg, opts: TOpts) => CommandResult | Promise; /** * Same as `mountResultCommand` but for commands that take exactly one * positional argument (e.g. `plugin add `). Commander passes * the positional arg before the parsed opts. */ export declare function mountResultCommandWithArg(cmd: Command, handler: CommandHandlerWithArg, opts: MountResultCommandOptions): void; /** * The shared `command-result` dispatch seam, extracted so the declarative * `mountCommandSpec` (the `output: 'command-result'` arm of `dispatchOutput`) and * the imperative `mountResultCommand` route a `CommandResult` through ONE point * instead of duplicating the json-short-circuit / `render` decision. * * launch (§5.5): the result is wrapped in a `CommandOutcome` (`.data`, or * `.errors` for an `ErrorResult`) and serialized through the single * `renderOutcome` seam. `--json` emits the whole outcome; human mode renders the * inner result through the supplied renderer — byte-identical to the prior human * output. Machine consumers must never see ANSI escapes, so the JSON path never * renders. */ export declare function emitCommandResult(result: CommandResult, opts: { readonly render: (result: CommandResult) => Promise; readonly jsonRequested: boolean; readonly exitCode?: number; }): Promise; //# sourceMappingURL=mount-result-command.d.ts.map