import { type Language } from "./strings.ts"; /** * The command line, as a pure function: arguments and surroundings in, what * to print and the exit code out. `bin/toranpu.mjs` is the few lines that * hand it the real process. Nothing here touches a file, a terminal or the * network, so every line of it is tested as plain data. */ /** What the command line is run in. All of it is optional. * * @example * ```ts * import type { CliSurroundings } from "@johnmorrisdotca/toranpu"; * * const value: CliSurroundings = { env: {}, locale: "en", colour: false, seed: () => 42 }; * console.log(value.locale); * ``` */ export type CliSurroundings = { /** The environment, for the language (`LC_ALL`, `LC_MESSAGES`, `LANG`) and `NO_COLOR`. */ env?: Record; /** Standard input, when `--stdin` asks for it: a saved game. */ stdin?: string; /** Reads a file named on the command line, or gives null when it cannot be read. `check` needs it; nothing else does. */ readFile?: (path: string) => string | null; /** Whether the output is a terminal that shows colour. `NO_COLOR` and `--no-color` still turn it off. */ colour?: boolean; /** The system's language where the environment names none: what `Intl` says, on Windows. */ locale?: string; /** Where a seed comes from when none is given: a function that returns a whole number from 1. `randomSeed` unless given. */ seed?: () => number; }; /** What the command line came to. * * @example * ```ts * import type { CliResult } from "@johnmorrisdotca/toranpu"; * import { runCli } from "@johnmorrisdotca/toranpu"; * * const value: CliResult = runCli(["--help"]); * console.log(value.code); * ``` */ export type CliResult = { /** 0 when all went well, 1 when what was asked for could not be done, 2 when the command itself was wrong. */ code: 0 | 1 | 2; /** For standard output. */ out: string; /** For standard error. */ err: string; }; /** The language the command line speaks: `--lang`, or the environment's, or the system's; Japanese for `ja…`, English for anything else. * * @param flag - An explicit language flag, when supplied. * @param env - Environment variables used to select the CLI language. * @param locale - The host locale used when no explicit language is supplied. * @returns The language the command line speaks: `--lang`, or the environment's, or the system's; Japanese for `ja…`, English for anything else. * * @example * ```ts * import { cliLanguage } from "@johnmorrisdotca/toranpu"; * * console.log(cliLanguage(undefined, { LANG: "ja_JP.UTF-8" })); * ``` */ export declare function cliLanguage(flag: string | undefined, env?: Record, locale?: string): Language; /** * Run the command line. See `toranpu --help` for what it takes. Every deal * comes from the seed, so the same command prints the same cards on every * machine. * * @param args - Arguments after the command name. * @param around - Environment, locale, input and random source supplied by the host. * @returns Run the command line. See `toranpu --help` for what it takes. Every deal comes from the seed, so the same command prints the same cards on every machine. * * @example * ```ts * import { runCli } from "@johnmorrisdotca/toranpu"; * * console.log(runCli(["--help"], { colour: false }).code); * ``` */ export declare function runCli(args: readonly string[], around?: CliSurroundings): CliResult;