IF Commons GitHub

surfaces/cli/prompts

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-headless-cli FR-006

Questions to the person (commons headless 0004-headless-cli FR-006): ask and confirm write the question to the person and read one line. With no terminal on both ends (a pipe, a timer, a service), or when the run was told never to ask, they ask no one and answer undefined, so that the caller falls back on the governance's decision (decide) instead of waiting on input that will never come. A confirmation is true only for a plain yes; anything else, including nothing, is no.

import { promptOf } from "./prompts.ts";
const p = promptOf({ interactive: false, readLine: async () => "y", write: () => {} });
await p.confirm("Delete?"); // undefined: there is no one to ask

Source: commons/headless/src/surfaces/cli/prompts.ts

2 of 3 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

PromptPortstypeno test imports it
type PromptPorts = {
  readonly interactive: boolean;
  readonly readLine: () => Promise<string | undefined>;
  readonly write: (text: string) => void;
};

What a prompt needs: whether a person can be asked, where the question is written (the error stream, so that a report on standard output stays clean), and the input.

isYesfunction
function isYes(line: string): boolean

Whether a line is a yes.

Imported by 16 tests of the run (16 passed, 0 failed): the library's results

promptOffunction
function promptOf(p: PromptPorts): Prompt

The prompt of a run.

Imported by 16 tests of the run (16 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.