API reference
caique/binding
Every export of caique/binding, with its signature and doc comment: resolvePrompts, localise, plus 4 types.
Resolving a whole command's prompts in one pass (R2, R3) — the piece a framework calls
from its preAction hook, after the environment and config layers have had their turn.
import { resolvePrompts, localise } from 'caique/binding';Functions
resolvePrompts
function resolvePrompts<O extends PromptableOption>({ options, values, runtime, flags, io }: ResolveInput<O>): Promise<Resolved>;| Parameter | Type |
|---|---|
{ options, values, runtime, flags, io } | ResolveInput<O> |
Returns Promise<Resolved>
Constants
localise
A failure with its translation beside it (R6). say is the identity unless a pack speaks the
run's locale (sayFor returns String itself then). A failure without a fix gets none.
const localise: (failure: ResolveFailure, say: (english: string) => string) => ResolveFailure;Interfaces
PromptableOption
What a host tells us about one option. Structural: any framework's spec satisfies it.
interface PromptableOption {
required?: boolean;
prompt?: PromptSpec;
/**
* How a refusal names it when `--<option>` is not how it is passed: `<name>` for a
* positional, `--dry-run` for a host's camelCase `dryRun` key (R1, `promptFor`).
*/
flag?: string;
}Resolved
interface Resolved {
/** The values with every answered prompt written in. The input is not mutated. */
values: Record<string, unknown>;
/**
* The first refusal, or nothing. First rather than all: the caller is about to exit, and
* a person told about six missing flags one of which they will answer interactively has
* been given a worse message than one told about the first.
*/
failure?: ResolveFailure;
}ResolveFailure
interface ResolveFailure {
option: string;
code: 'USAGE' | 'CANCELLED';
message: string;
fix?: string;
/**
* `message` and `fix` in `runtime.locale`, when a registered pack speaks it
* (`localised-human-surfaces` R6). Beside them and not in place of them: a refusal is a value a
* host may write into a machine envelope, and those stay in English whatever the locale.
*/
localised?: {
message: string;
fix?: string;
};
}ResolveInput
interface ResolveInput<O extends PromptableOption = PromptableOption> {
/** The command's options by name, in declaration order — a record preserves it. */
options: Record<string, O>;
/** What the values are after every other source has been consulted. */
values: Record<string, unknown>;
runtime: Runtime;
flags?: Flags;
io: Io;
}