# caique/binding

> Every export of caique/binding, with its signature and doc comment: resolvePrompts, plus 4 types.

Source: https://caique.interlace.tools/docs/api/binding

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

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.

The design sketched this as `caique/burgee`, one binding per host. It is one binding for
all of them instead, and that is the better answer: what a host actually supplies is a
record of options, the values parsed so far, and a runtime. None of that needs burgee's
types, so nothing here imports them — which keeps the family's rule that no package
requires another, and means `burgee`, `burgee/commander` and `burgee/yargs` share one
implementation rather than three that drift.

The order is the declaration order, because `--interactive` asks for several things at
once and a person answering them needs the sequence to match the help they just read.

```ts
import { resolvePrompts } from 'caique/binding';
```

## Functions

### resolvePrompts

Walk the command's options in order, asking only what has to be asked.

Stops at the first refusal: the caller is about to exit, and a person told about six
missing flags — one of which they would have answered interactively — has been given a
worse message than one told about the first.

```ts
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>`

## Interfaces

### PromptableOption

What a host tells us about one option. Structural: any framework's spec satisfies it.

```ts
interface PromptableOption {
    required?: boolean;
    prompt?: PromptSpec;
}
```

### Resolved

```ts
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

```ts
interface ResolveFailure {
    option: string;
    code: 'USAGE' | 'CANCELLED';
    message: string;
    fix?: string;
}
```

### ResolveInput

```ts
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;
}
```
