cli-kiss 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +696 -734
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/docs/.vitepress/config.mts +2 -3
- package/docs/.vitepress/theme/index.ts +4 -0
- package/docs/.vitepress/theme/style.css +4 -0
- package/docs/guide/01_getting_started.md +12 -13
- package/docs/guide/02_commands.md +71 -52
- package/docs/guide/03_options.md +25 -33
- package/docs/guide/04_positionals.md +45 -55
- package/docs/guide/05_types.md +66 -66
- package/docs/guide/06_run.md +28 -40
- package/docs/index.md +8 -3
- package/docs/public/favicon.ico +0 -0
- package/docs/public/hero.png +0 -0
- package/package.json +1 -1
- package/src/index.ts +0 -2
- package/src/lib/Command.ts +45 -123
- package/src/lib/Operation.ts +23 -32
- package/src/lib/Option.ts +150 -170
- package/src/lib/Positional.ts +44 -94
- package/src/lib/Reader.ts +123 -99
- package/src/lib/Run.ts +86 -45
- package/src/lib/Type.ts +246 -156
- package/src/lib/Typo.ts +98 -107
- package/src/lib/Usage.ts +163 -82
- package/tests/unit.Reader.aliases.ts +31 -15
- package/tests/unit.Reader.commons.ts +99 -43
- package/tests/unit.Reader.parsings.ts +50 -0
- package/tests/unit.Reader.shortBig.ts +75 -31
- package/tests/unit.command.execute.ts +86 -43
- package/tests/unit.command.usage.ts +88 -82
- package/tests/unit.runner.colors.ts +197 -0
- package/tests/unit.runner.cycle.ts +77 -63
- package/tests/unit.runner.errors.ts +23 -15
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/lib/Typo.ts","../src/lib/Command.ts","../src/lib/Operation.ts","../src/lib/Type.ts","../src/lib/Option.ts","../src/lib/Positional.ts","../src/lib/Reader.ts","../src/lib/Usage.ts","../src/lib/Run.ts"],"sourcesContent":["export * from \"./lib/Command\";\nexport * from \"./lib/Operation\";\nexport * from \"./lib/Option\";\nexport * from \"./lib/Positional\";\nexport * from \"./lib/Reader\";\nexport * from \"./lib/Run\";\nexport * from \"./lib/Type\";\nexport * from \"./lib/Typo\";\nexport * from \"./lib/Usage\";\n\n// TODO - maybe add a parsed option recap on error\n","/**\n * Color names for terminal styling, used by {@link TypoStyle}.\n * `dark*` = standard ANSI (30–37); `bright*` = high-intensity (90–97).\n */\nexport type TypoColor =\n | \"darkBlack\"\n | \"darkRed\"\n | \"darkGreen\"\n | \"darkYellow\"\n | \"darkBlue\"\n | \"darkMagenta\"\n | \"darkCyan\"\n | \"darkWhite\"\n | \"brightBlack\"\n | \"brightRed\"\n | \"brightGreen\"\n | \"brightYellow\"\n | \"brightBlue\"\n | \"brightMagenta\"\n | \"brightCyan\"\n | \"brightWhite\";\n\n/**\n * Visual styling applied by a {@link TypoSupport} instance.\n * All fields are optional; ignored entirely in `\"none\"` mode.\n */\nexport type TypoStyle = {\n /**\n * Foreground (text) color.\n */\n fgColor?: TypoColor;\n /**\n * Background color.\n */\n bgColor?: TypoColor;\n /**\n * Render with reduced intensity.\n */\n dim?: boolean;\n /**\n * Render in bold.\n */\n bold?: boolean;\n /**\n * Render in italic.\n */\n italic?: boolean;\n /**\n * Render with an underline.\n */\n underline?: boolean;\n /**\n * Render with a strikethrough.\n */\n strikethrough?: boolean;\n};\n\n/**\n * Pre-defined style for section titles (e.g. `\"Positionals:\"`). Bold dark-green.\n */\nexport const typoStyleTitle: TypoStyle = {\n fgColor: \"darkGreen\",\n bold: true,\n};\n/**\n * Pre-defined style for logic/type identifiers in error messages. Bold dark-magenta.\n */\nexport const typoStyleLogic: TypoStyle = {\n fgColor: \"darkMagenta\",\n bold: true,\n};\n/**\n * Pre-defined style for quoted user-supplied values in error messages. Bold dark-yellow.\n */\nexport const typoStyleQuote: TypoStyle = {\n fgColor: \"darkYellow\",\n bold: true,\n};\n\n/**\n * Pre-defined style for failure/error labels (e.g. `\"Error:\"`). Bold dark-red.\n */\nexport const typoStyleFailure: TypoStyle = {\n fgColor: \"darkRed\",\n bold: true,\n};\n\n/**\n * Pre-defined style for CLI flag/option/command names. Bold dark-cyan.\n */\nexport const typoStyleConstants: TypoStyle = {\n fgColor: \"darkCyan\",\n bold: true,\n};\n/**\n * Pre-defined style for positional placeholders and user-input labels. Bold dark-blue.\n */\nexport const typoStyleUserInput: TypoStyle = {\n fgColor: \"darkBlue\",\n bold: true,\n};\n\n/**\n * Pre-defined style for strong regular text (e.g. command descriptions). Bold.\n */\nexport const typoStyleRegularStrong: TypoStyle = {\n bold: true,\n};\n/**\n * Pre-defined style for subtle supplementary text (e.g. hints). Italic and dim.\n */\nexport const typoStyleRegularWeaker: TypoStyle = {\n italic: true,\n dim: true,\n};\n\n/**\n * An immutable styled string segment: a raw text value paired with a {@link TypoStyle}.\n * Compose multiple segments into a {@link TypoText}; rendering is deferred to {@link TypoString.computeStyledString}.\n */\nexport class TypoString {\n #value: string;\n #typoStyle: TypoStyle;\n /**\n * @param value - Raw text content.\n * @param typoStyle - Style to apply when rendering. Defaults to `{}` (no style).\n */\n constructor(value: string, typoStyle: TypoStyle = {}) {\n this.#value = value;\n this.#typoStyle = typoStyle;\n }\n /**\n * Returns the unstyled raw text content.\n */\n getRawString(): string {\n return this.#value;\n }\n /**\n * Returns the text styled by `typoSupport`.\n *\n * @param typoSupport - Rendering mode.\n */\n computeStyledString(typoSupport: TypoSupport): string {\n return typoSupport.computeStyledString(this.#value, this.#typoStyle);\n }\n}\n\n/**\n * A mutable sequence of {@link TypoString} segments forming a styled multi-part message.\n * Rendering is deferred to {@link TypoText.computeStyledString}.\n */\nexport class TypoText {\n #typoStrings: Array<TypoString>;\n /**\n * @param typoParts - Initial segments; `TypoText` is flattened, `string` is wrapped unstyled.\n */\n constructor(...typoParts: Array<TypoText | TypoString | string>) {\n this.#typoStrings = [];\n for (const typoPart of typoParts) {\n if (typoPart instanceof TypoText) {\n this.pushText(typoPart);\n } else if (typoPart instanceof TypoString) {\n this.pushString(typoPart);\n } else if (typeof typoPart === \"string\") {\n this.pushString(new TypoString(typoPart));\n }\n }\n }\n /**\n * Appends a {@link TypoString} segment.\n *\n * @param typoString - Segment to append.\n */\n pushString(typoString: TypoString | string) {\n if (typeof typoString === \"string\") {\n this.#typoStrings.push(new TypoString(typoString));\n } else {\n this.#typoStrings.push(typoString);\n }\n }\n /**\n * Appends all segments from another {@link TypoText} (shallow copy).\n *\n * @param typoText - Source text.\n */\n pushText(typoText: TypoText | string) {\n if (typeof typoText === \"string\") {\n this.pushString(typoText);\n } else {\n for (const typoString of typoText.#typoStrings) {\n this.#typoStrings.push(typoString);\n }\n }\n }\n /**\n * Renders all segments into a single styled string.\n *\n * @param typoSupport - Rendering mode.\n * @returns Concatenated styled string.\n */\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoStrings\n .map((t) => t.computeStyledString(typoSupport))\n .join(\"\");\n }\n /**\n * Returns the concatenation of all segments' raw (unstyled) text.\n */\n computeRawString(): string {\n return this.#typoStrings.map((t) => t.getRawString()).join(\"\");\n }\n /**\n * Returns the total character count of the raw (unstyled) text.\n */\n computeRawLength(): number {\n let length = 0;\n for (const typoString of this.#typoStrings) {\n length += typoString.getRawString().length;\n }\n return length;\n }\n}\n\n/**\n * A column-aligned grid of {@link TypoText} cells.\n * Each column is padded to the widest cell (raw chars); the last column is not padded.\n * Used by {@link usageToStyledLines} to render `Positionals:`, `Subcommands:`, and `Options:`.\n */\nexport class TypoGrid {\n #typoRows: Array<Array<TypoText>>;\n constructor() {\n this.#typoRows = [];\n }\n /**\n * Appends a row. All rows should have the same cell count for alignment to be meaningful.\n *\n * @param cells - Ordered {@link TypoText} cells.\n */\n pushRow(cells: Array<TypoText>) {\n this.#typoRows.push(cells);\n }\n /**\n * Renders the grid as a 2-D array of styled (and column-padded) strings.\n * Join each inner array with `\"\"` to get a line.\n *\n * @param typoSupport - Rendering mode.\n * @returns 2-D array of styled strings.\n */\n computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>> {\n const widths = new Array<number>();\n const printableGrid = new Array<Array<string>>();\n for (const typoGridRow of this.#typoRows) {\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const width = typoGridCell.computeRawLength();\n if (\n widths[typoGridColumnIndex] === undefined ||\n width > widths[typoGridColumnIndex]!\n ) {\n widths[typoGridColumnIndex] = width;\n }\n }\n }\n for (const typoGridRow of this.#typoRows) {\n const printableGridRow = new Array<string>();\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const printableGridCell = typoGridCell.computeStyledString(typoSupport);\n printableGridRow.push(printableGridCell);\n if (typoGridColumnIndex < typoGridRow.length - 1) {\n const width = typoGridCell.computeRawLength();\n const padding = \" \".repeat(widths[typoGridColumnIndex]! - width);\n printableGridRow.push(padding);\n }\n }\n printableGrid.push(printableGridRow);\n }\n return printableGrid;\n }\n}\n\n/**\n * `Error` subclass with a {@link TypoText} styled message for rich terminal output.\n * Used throughout the library for parse failures (unknown option, type decode error, etc.).\n * If `source` is a `TypoError`, its styled text is chained after `\": \"`.\n */\nexport class TypoError extends Error {\n #typoText: TypoText;\n /**\n * @param currentTypoText - Styled message for this error.\n * @param source - Optional cause; `TypoError` chains styled text, `Error` appends `.message`, else `String()`.\n */\n constructor(currentTypoText: TypoText, source?: unknown) {\n const typoText = new TypoText();\n typoText.pushText(currentTypoText);\n if (source instanceof TypoError) {\n typoText.pushString(new TypoString(\": \"));\n typoText.pushText(source.#typoText);\n } else if (source instanceof Error) {\n typoText.pushString(new TypoString(`: ${source.message}`));\n } else if (source !== undefined) {\n typoText.pushString(new TypoString(`: ${String(source)}`));\n }\n super(typoText.computeRawString());\n this.#typoText = typoText;\n }\n /**\n * Renders the styled error message (without a `\"Error:\"` prefix).\n *\n * @param typoSupport - Rendering mode.\n * @returns Styled error string.\n */\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoText.computeStyledString(typoSupport);\n }\n /**\n * Runs `thrower`; on any throw wraps it as a `TypoError` with `context()` prepended.\n * Useful for adding call-chain context (e.g. `\"at 0: Number: ...\"`).\n *\n * @typeParam Value - Return type of `thrower`.\n * @param thrower - Function to execute; result passed through on success.\n * @param context - Produces the {@link TypoText} prepended to the caught error.\n * @returns Value from `thrower`.\n * @throws `TypoError` wrapping the original error with context prepended.\n */\n static tryWithContext<Value>(\n thrower: () => Value,\n context: () => TypoText,\n ): Value {\n try {\n return thrower();\n } catch (error) {\n throw new TypoError(context(), error);\n }\n }\n}\n\n/**\n * Controls ANSI terminal styling for {@link TypoString}, {@link TypoText}, and error rendering.\n * Create via {@link TypoSupport.none}, {@link TypoSupport.tty}, {@link TypoSupport.mock},\n * or {@link TypoSupport.inferFromProcess}.\n */\nexport class TypoSupport {\n #kind: \"none\" | \"tty\" | \"mock\";\n private constructor(kind: \"none\" | \"tty\" | \"mock\") {\n this.#kind = kind;\n }\n /**\n * Returns a `TypoSupport` that strips all styling (plain text, no ANSI codes).\n */\n static none(): TypoSupport {\n return new TypoSupport(\"none\");\n }\n /**\n * Returns a `TypoSupport` that applies ANSI escape codes (for color-capable terminals).\n */\n static tty(): TypoSupport {\n return new TypoSupport(\"tty\");\n }\n /**\n * Returns a `TypoSupport` with deterministic textual styling for snapshot tests.\n * Style flags appear as suffixes: `{text}@color`, `{text}+` (bold), `{text}-` (dim),\n * `{text}*` (italic), `{text}_` (underline), `{text}~` (strikethrough).\n */\n static mock(): TypoSupport {\n return new TypoSupport(\"mock\");\n }\n /**\n * Auto-detects styling mode from the process environment.\n * `FORCE_COLOR=0` / `NO_COLOR` → none; `FORCE_COLOR` (truthy) / `isTTY` → tty; else → none.\n * Falls back to none if `process` is unavailable.\n */\n static inferFromProcess(): TypoSupport {\n if (!process) {\n return TypoSupport.none();\n }\n if (process.env) {\n if (process.env[\"FORCE_COLOR\"] === \"0\") {\n return TypoSupport.none();\n }\n if (process.env[\"FORCE_COLOR\"]) {\n return TypoSupport.tty();\n }\n if (\"NO_COLOR\" in process.env) {\n return TypoSupport.none();\n }\n }\n if (process.stdout && process.stdout.isTTY) {\n return TypoSupport.tty();\n }\n return TypoSupport.none();\n }\n /**\n * Applies `typoStyle` to `value` according to the current mode.\n *\n * @param value - Raw text.\n * @param typoStyle - Style to apply.\n * @returns Styled string.\n */\n computeStyledString(value: string, typoStyle: TypoStyle): string {\n if (this.#kind === \"none\") {\n return value;\n }\n if (this.#kind === \"tty\") {\n const fgColorCode = typoStyle.fgColor\n ? ttyCodeFgColors[typoStyle.fgColor]\n : \"\";\n const bgColorCode = typoStyle.bgColor\n ? ttyCodeBgColors[typoStyle.bgColor]\n : \"\";\n const boldCode = typoStyle.bold ? ttyCodeBold : \"\";\n const dimCode = typoStyle.dim ? ttyCodeDim : \"\";\n const italicCode = typoStyle.italic ? ttyCodeItalic : \"\";\n const underlineCode = typoStyle.underline ? ttyCodeUnderline : \"\";\n const strikethroughCode = typoStyle.strikethrough\n ? ttyCodeStrikethrough\n : \"\";\n return `${fgColorCode}${bgColorCode}${boldCode}${dimCode}${italicCode}${underlineCode}${strikethroughCode}${value}${ttyCodeReset}`;\n }\n if (this.#kind === \"mock\") {\n const fgColorPart = typoStyle.fgColor\n ? `{${value}}@${typoStyle.fgColor}`\n : value;\n const bgColorPart = typoStyle.bgColor\n ? `{${fgColorPart}}#${typoStyle.bgColor}`\n : fgColorPart;\n const boldPart = typoStyle.bold ? `{${bgColorPart}}+` : bgColorPart;\n const dimPart = typoStyle.dim ? `{${boldPart}}-` : boldPart;\n const italicPart = typoStyle.italic ? `{${dimPart}}*` : dimPart;\n const underlinePart = typoStyle.underline\n ? `{${italicPart}}_`\n : italicPart;\n const strikethroughPart = typoStyle.strikethrough\n ? `{${underlinePart}}~`\n : underlinePart;\n return strikethroughPart;\n }\n throw new Error(`Unknown TypoSupport kind: ${this.#kind}`);\n }\n /**\n * Formats any thrown value as `\"Error: <message>\"` with {@link typoStyleFailure} on the prefix.\n *\n * @param error - Any thrown value.\n * @returns Styled error string.\n */\n computeStyledErrorMessage(error: unknown): string {\n return [\n this.computeStyledString(\"Error:\", typoStyleFailure),\n error instanceof TypoError\n ? error.computeStyledString(this)\n : error instanceof Error\n ? error.message\n : String(error),\n ].join(\" \");\n }\n}\n\nconst ttyCodeReset = \"\\x1b[0m\";\nconst ttyCodeBold = \"\\x1b[1m\";\nconst ttyCodeDim = \"\\x1b[2m\";\nconst ttyCodeItalic = \"\\x1b[3m\";\nconst ttyCodeUnderline = \"\\x1b[4m\";\nconst ttyCodeStrikethrough = \"\\x1b[9m\";\nconst ttyCodeFgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[30m\",\n darkRed: \"\\x1b[31m\",\n darkGreen: \"\\x1b[32m\",\n darkYellow: \"\\x1b[33m\",\n darkBlue: \"\\x1b[34m\",\n darkMagenta: \"\\x1b[35m\",\n darkCyan: \"\\x1b[36m\",\n darkWhite: \"\\x1b[37m\",\n brightBlack: \"\\x1b[90m\",\n brightRed: \"\\x1b[91m\",\n brightGreen: \"\\x1b[92m\",\n brightYellow: \"\\x1b[93m\",\n brightBlue: \"\\x1b[94m\",\n brightMagenta: \"\\x1b[95m\",\n brightCyan: \"\\x1b[96m\",\n brightWhite: \"\\x1b[97m\",\n};\nconst ttyCodeBgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[40m\",\n darkRed: \"\\x1b[41m\",\n darkGreen: \"\\x1b[42m\",\n darkYellow: \"\\x1b[43m\",\n darkBlue: \"\\x1b[44m\",\n darkMagenta: \"\\x1b[45m\",\n darkCyan: \"\\x1b[46m\",\n darkWhite: \"\\x1b[47m\",\n brightBlack: \"\\x1b[100m\",\n brightRed: \"\\x1b[101m\",\n brightGreen: \"\\x1b[102m\",\n brightYellow: \"\\x1b[103m\",\n brightBlue: \"\\x1b[104m\",\n brightMagenta: \"\\x1b[105m\",\n brightCyan: \"\\x1b[106m\",\n brightWhite: \"\\x1b[107m\",\n};\n","import { Operation } from \"./Operation\";\nimport { OptionUsage } from \"./Option\";\nimport { PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\nimport {\n TypoError,\n TypoString,\n typoStyleQuote,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\n\n/**\n * A CLI command — parses arguments and executes within a given context.\n * Created with {@link command}, {@link commandWithSubcommands}, or {@link commandChained}.\n * Usually passed through {@link runAndExit} to run.\n *\n * @typeParam Context - Injected at execution time; forwarded to handlers. Use to inject dependencies.\n * @typeParam Result - Value produced on execution; typically `void` for leaf commands.\n */\nexport type Command<Context, Result> = {\n /**\n * Returns the command's static metadata.\n */\n getInformation(): CommandInformation;\n /**\n * Consumes args in a `readerArgs` and returns a {@link CommandDecoder}.\n */\n consumeAndMakeDecoder(\n readerArgs: ReaderArgs,\n ): CommandDecoder<Context, Result>;\n};\n\n/**\n * Produced by {@link Command.consumeAndMakeDecoder}.\n *\n * @typeParam Context - See {@link Command}.\n * @typeParam Result - See {@link Command}.\n */\nexport type CommandDecoder<Context, Result> = {\n /**\n * Builds the {@link CommandUsage} for the current command path.\n * Used for `--help` and `usageOnError`.\n */\n generateUsage(): CommandUsage;\n /**\n * Creates a ready-to-execute {@link CommandInterpreter}.\n *\n * @throws {@link TypoError} if parsing or decoding failed.\n */\n decodeAndMakeInterpreter(): CommandInterpreter<Context, Result>;\n};\n\n/**\n * A fully parsed, decoded and ready-to-execute command.\n *\n * @typeParam Context - Caller-supplied context.\n * @typeParam Result - Value produced on success.\n */\nexport type CommandInterpreter<Context, Result> = {\n /**\n * Executes with the provided context.\n */\n executeWithContext(context: Context): Promise<Result>;\n};\n\n/**\n * Static metadata for a command, shown in `--help` output via {@link usageToStyledLines}.\n */\nexport type CommandInformation = {\n /**\n * Short description shown in the usage header.\n */\n description: string;\n /**\n * Short note shown in parentheses (e.g. `\"deprecated\"`, `\"experimental\"`).\n */\n hint?: string;\n /**\n * Extra lines printed below the description.\n */\n details?: Array<string>;\n /**\n * Examples shown in the `Examples:` section of the usage output.\n */\n examples?: Array<{\n /**\n * Explanation shown above the example.\n */\n explanation: string;\n /**\n * Command line args to show as an example of usage.\n */\n commandArgs: Array<\n | string\n | { positional: string }\n | { subcommand: string }\n | {\n option:\n | { long: string; value?: string }\n | { short: string; value?: string };\n }\n >;\n }>;\n};\n\n/**\n * Full usage/help model.\n * Produced by {@link CommandDecoder.generateUsage},\n * Consumed by {@link usageToStyledLines}.\n */\nexport type CommandUsage = {\n /**\n * Segments forming the usage line\n * (e.g. `my-cli <POSITIONAL> subcommand <ANOTHER_POSITIONAL>`).\n */\n segments: Array<CommandUsageSegment>;\n /**\n * Command's static metadata.\n */\n information: CommandInformation;\n /**\n * Positionals in declaration order.\n */\n positionals: Array<PositionalUsage>;\n /**\n * Available subcommands. Non-empty when subcommand was not specified.\n */\n subcommands: Array<CommandUsageSubcommand>;\n /**\n * Options in registration order.\n */\n options: Array<OptionUsage>;\n};\n\n/**\n * One element in the usage segment trail.\n */\nexport type CommandUsageSegment = { positional: string } | { command: string };\n\n/**\n * Subcommand entry shown in the `Subcommands:` section of the usage output.\n */\nexport type CommandUsageSubcommand = {\n /**\n * Literal token the user types (e.g. `\"deploy\"`).\n */\n name: string;\n /**\n * Short description from the subcommand's {@link CommandInformation}.\n */\n description: string | undefined;\n /**\n * Hint from the subcommand's {@link CommandInformation}.\n */\n hint: string | undefined;\n};\n\n/**\n * Creates a leaf command that directly executes an {@link Operation}.\n *\n * @typeParam Context - Context forwarded to the handler.\n * @typeParam Result - Value returned by the handler.\n *\n * @param information - Command metadata (description, hint, details).\n * @param operation - Defines: options, positionals, and the handler.\n * @returns A {@link Command}.\n *\n * @example\n * ```ts\n * const greet = command(\n * { description: \"Greet a user\" },\n * operation(\n * { options: {}, positionals: [positionalRequired({ type: typeString, label: \"NAME\" })] },\n * async (_ctx, { positionals: [name] }) => console.log(`Hello, ${name}!`),\n * ),\n * );\n * ```\n */\nexport function command<Context, Result>(\n information: CommandInformation,\n operation: Operation<Context, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n try {\n const operationDecoder = operation.consumeAndMakeDecoder(readerArgs);\n const endPositional = readerArgs.consumePositional();\n if (endPositional !== undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Unexpected argument: `),\n new TypoString(`\"${endPositional}\"`, typoStyleQuote),\n ),\n );\n }\n return {\n generateUsage: () => generateUsageShallow(information, operation),\n decodeAndMakeInterpreter() {\n const operationInterpreter =\n operationDecoder.decodeAndMakeInterpreter();\n return {\n async executeWithContext(context: Context) {\n return await operationInterpreter.executeWithContext(context);\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage: () => generateUsageShallow(information, operation),\n decodeAndMakeInterpreter() {\n throw error;\n },\n };\n }\n },\n };\n}\n\n/**\n * Creates a command that runs an {@link Operation} to produce a `Payload`,\n * then dispatches to a named subcommand based on the next positional token.\n *\n * @typeParam Context - Context accepted by `operation`.\n * @typeParam Payload - Output of `operation`; becomes the subcommand's context.\n * @typeParam Result - Value produced by the selected subcommand.\n *\n * @param information - Command metadata (description, hint, details).\n * @param operation - Always runs first; its output becomes the subcommand's context.\n * @param subcommands - Map of subcommand names to their {@link Command}s.\n * @returns A {@link Command} that dispatches to one of the provided subcommands.\n *\n * @example\n * ```ts\n * const rootCmd = commandWithSubcommands(\n * { description: \"My CLI\" },\n * operation({ options: {}, positionals: [] }, async (ctx) => ctx),\n * {\n * deploy: command({ description: \"Deploy\" }, deployOperation),\n * rollback: command({ description: \"Rollback\" }, rollbackOperation),\n * },\n * );\n * ```\n */\nexport function commandWithSubcommands<Context, Payload, Result>(\n information: CommandInformation,\n operation: Operation<Context, Payload>,\n subcommands: { [subcommand: Lowercase<string>]: Command<Payload, Result> },\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n try {\n const operationDecoder = operation.consumeAndMakeDecoder(readerArgs);\n const subcommandName = readerArgs.consumePositional();\n if (subcommandName === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n const subcommandInput =\n subcommands[subcommandName as Lowercase<string>];\n if (subcommandInput === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<SUBCOMMAND>`, typoStyleUserInput),\n new TypoString(`: Invalid value: `),\n new TypoString(`\"${subcommandName}\"`, typoStyleQuote),\n ),\n );\n }\n const subcommandDecoder =\n subcommandInput.consumeAndMakeDecoder(readerArgs);\n return {\n generateUsage() {\n const subcommandUsage = subcommandDecoder.generateUsage();\n const currentUsage = generateUsageShallow(information, operation);\n currentUsage.segments.push(segmentCommand(subcommandName));\n currentUsage.segments.push(...subcommandUsage.segments);\n currentUsage.information = subcommandUsage.information;\n currentUsage.positionals.push(...subcommandUsage.positionals);\n currentUsage.subcommands = subcommandUsage.subcommands;\n currentUsage.options.push(...subcommandUsage.options);\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n const operationInterpreter =\n operationDecoder.decodeAndMakeInterpreter();\n const subcommandInterpreter =\n subcommandDecoder.decodeAndMakeInterpreter();\n return {\n async executeWithContext(context: Context) {\n return await subcommandInterpreter.executeWithContext(\n await operationInterpreter.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const currentUsage = generateUsageShallow(information, operation);\n currentUsage.segments.push(segmentPositional(\"<SUBCOMMAND>\"));\n for (const [name, subcommand] of Object.entries(subcommands)) {\n const { description, hint } = subcommand.getInformation();\n currentUsage.subcommands.push({ name, description, hint });\n }\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n throw error;\n },\n };\n }\n },\n };\n}\n\n/**\n * Chains an {@link Operation} and a {@link Command}: `operation` runs first, its\n * output becomes `subcommand`'s context. No token is consumed for routing.\n *\n * @typeParam Context - Context accepted by `operation`.\n * @typeParam Payload - Output of `operation`; becomes `subcommand`'s context.\n * @typeParam Result - Value produced by `subcommand`.\n *\n * @param information - Command metadata (description, hint, details).\n * @param operation - First stage; its output is passed as `subcommand`'s context.\n * @param subcommand - Second stage, executed after `operation`.\n * @returns A {@link Command} transparently composing the two stages.\n *\n * @example\n * ```ts\n * const authenticatedDeploy = commandChained(\n * { description: \"Authenticate then deploy\" },\n * operation(\n * { options: { token: optionSingleValue({ long: \"token\", type: typeString, default: () => \"\" }) }, positionals: [] },\n * async (_ctx, { options: { token } }) => ({ token }),\n * ),\n * command({ description: \"Deploy\" }, deployOperation),\n * );\n * ```\n */\nexport function commandChained<Context, Payload, Result>(\n information: CommandInformation,\n operation: Operation<Context, Payload>,\n subcommand: Command<Payload, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n try {\n const operationDecoder = operation.consumeAndMakeDecoder(readerArgs);\n const subcommandDecoder = subcommand.consumeAndMakeDecoder(readerArgs);\n return {\n generateUsage() {\n const subcommandUsage = subcommandDecoder.generateUsage();\n const currentUsage = generateUsageShallow(information, operation);\n currentUsage.segments.push(...subcommandUsage.segments);\n currentUsage.information = subcommandUsage.information;\n currentUsage.positionals.push(...subcommandUsage.positionals);\n currentUsage.subcommands = subcommandUsage.subcommands;\n currentUsage.options.push(...subcommandUsage.options);\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n const operationInterpreter =\n operationDecoder.decodeAndMakeInterpreter();\n const subcommandInterpreter =\n subcommandDecoder.decodeAndMakeInterpreter();\n return {\n async executeWithContext(context: Context) {\n return await subcommandInterpreter.executeWithContext(\n await operationInterpreter.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const currentUsage = generateUsageShallow(information, operation);\n currentUsage.segments.push(segmentPositional(\"[REST]...\"));\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nfunction segmentPositional(value: string): CommandUsageSegment {\n return { positional: value };\n}\n\nfunction segmentCommand(value: string): CommandUsageSegment {\n return { command: value };\n}\n\nfunction generateUsageShallow(\n information: CommandInformation,\n operation: Operation<any, any>,\n): CommandUsage {\n const { positionals, options } = operation.generateUsage();\n return {\n segments: positionals.map((positional) =>\n segmentPositional(positional.label),\n ),\n information,\n positionals,\n subcommands: [],\n options,\n };\n}\n","import { Option, OptionDecoder, OptionUsage } from \"./Option\";\nimport { Positional, PositionalDecoder, PositionalUsage } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\n\n/**\n * Options, positionals, and an async handler that together form the logic of a CLI command.\n *\n * Created with {@link operation} and passed to {@link command},\n * {@link commandWithSubcommands}, or {@link commandChained}.\n *\n * @typeParam Context - Injected at execution time; forwarded to handlers. Use to inject dependencies.\n * @typeParam Result - Value produced on execution; typically `void` for leaf commands.\n */\nexport type Operation<Context, Result> = {\n /**\n * Returns usage metadata without consuming any arguments.\n */\n generateUsage(): OperationUsage;\n /**\n * Consumes args from `readerArgs` and returns an {@link OperationDecoder}.\n */\n consumeAndMakeDecoder(\n readerArgs: ReaderArgs,\n ): OperationDecoder<Context, Result>;\n};\n\n/**\n * Produced by {@link Operation.consumeAndMakeDecoder}.\n *\n * @typeParam Context - See {@link Operation}.\n * @typeParam Result - See {@link Operation}.\n */\nexport type OperationDecoder<Context, Result> = {\n /**\n * Creates a ready-to-execute {@link OperationInterpreter}.\n *\n * @throws {@link TypoError} if parsing or decoding failed.\n */\n decodeAndMakeInterpreter(): OperationInterpreter<Context, Result>;\n};\n\n/**\n * A fully parsed, decoded and ready-to-execute operation.\n *\n * @typeParam Context - Caller-supplied context.\n * @typeParam Result - Value produced on success.\n */\nexport type OperationInterpreter<Context, Result> = {\n /**\n * Executes with the provided context.\n */\n executeWithContext(context: Context): Promise<Result>;\n};\n\n/**\n * Usage metadata produced by {@link Operation.generateUsage}.\n * Consumed when building {@link CommandUsage}.\n */\nexport type OperationUsage = {\n /**\n * Usage descriptors for all registered options.\n */\n options: Array<OptionUsage>;\n /**\n * Usage descriptors for all declared positionals, in order.\n */\n positionals: Array<PositionalUsage>;\n};\n\n/**\n * Creates an {@link Operation} from options, positionals, and an async handler.\n *\n * The `handler` receives the parent `context` and an `inputs` object with\n * `options` (keyed by the same names declared in `inputs.options`) and\n * `positionals` (a tuple in declaration order).\n *\n * @typeParam Context - Context type accepted by the handler.\n * @typeParam Result - Return type of the handler.\n * @typeParam Options - Map of option keys to parsed value types.\n * @typeParam Positionals - Tuple of parsed positional value types, in order.\n *\n * @param inputs - Options and positionals this operation accepts.\n * @param inputs.options - Map of keys to {@link Option} descriptors.\n * @param inputs.positionals - Ordered array of {@link Positional} descriptors.\n * @param handler - Async function implementing the command logic.\n * @returns An {@link Operation} ready to be composed into a command.\n *\n * @example\n * ```ts\n * const greetOperation = operation(\n * {\n * options: {\n * loud: optionFlag({ long: \"loud\", description: \"Print in uppercase\" }),\n * },\n * positionals: [\n * positionalRequired({ type: typeString, label: \"NAME\", description: \"Name to greet\" }),\n * ],\n * },\n * async (_ctx, { options: { loud }, positionals: [name] }) => {\n * const message = `Hello, ${name}!`;\n * console.log(loud ? message.toUpperCase() : message);\n * },\n * );\n * ```\n */\nexport function operation<\n Context,\n Result,\n Options extends { [option: string]: any },\n const Positionals extends Array<any>,\n>(\n inputs: {\n options: { [K in keyof Options]: Option<Options[K]> };\n positionals: { [K in keyof Positionals]: Positional<Positionals[K]> };\n },\n handler: (\n context: Context,\n inputs: {\n options: Options;\n positionals: Positionals;\n },\n ) => Promise<Result>,\n): Operation<Context, Result> {\n return {\n generateUsage() {\n const optionsUsage = new Array<OptionUsage>();\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n if (optionInput) {\n optionsUsage.push(optionInput.generateUsage());\n }\n }\n const positionalsUsage = new Array<PositionalUsage>();\n for (const positionalInput of inputs.positionals) {\n positionalsUsage.push(positionalInput.generateUsage());\n }\n return { options: optionsUsage, positionals: positionalsUsage };\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n const optionsDecoders: Record<string, OptionDecoder<any>> = {};\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n optionsDecoders[optionKey] =\n optionInput.registerAndMakeDecoder(readerArgs);\n }\n const positionalsDecoders: Array<PositionalDecoder<any>> = [];\n for (const positionalInput of inputs.positionals) {\n positionalsDecoders.push(\n positionalInput.consumeAndMakeDecoder(readerArgs),\n );\n }\n return {\n decodeAndMakeInterpreter() {\n const optionsValues: any = {};\n for (const optionKey in optionsDecoders) {\n optionsValues[optionKey] =\n optionsDecoders[optionKey]!.getAndDecodeValue();\n }\n const positionalsValues: any = [];\n for (const positionalDecoder of positionalsDecoders) {\n positionalsValues.push(positionalDecoder.decodeValue());\n }\n return {\n executeWithContext(context: Context) {\n return handler(context, {\n options: optionsValues,\n positionals: positionalsValues,\n });\n },\n };\n },\n };\n },\n };\n}\n","import {\n TypoError,\n TypoString,\n typoStyleLogic,\n typoStyleQuote,\n TypoText,\n} from \"./Typo\";\n\n/**\n * Decodes a raw CLI string into a typed value.\n * A pair of a human-readable `content` name (e.g. `\"Number\"`) and a `decoder` function.\n *\n * Built-in: {@link typeString}, {@link typeBoolean}, {@link typeNumber},\n * {@link typeInteger}, {@link typeDate}, {@link typeUrl}.\n * Composite: {@link typeOneOf}, {@link typeMapped}, {@link typeTuple}, {@link typeList}.\n *\n * @typeParam Value - Type produced by the decoder.\n */\nexport type Type<Value> = {\n /**\n * Human-readable name shown in help and error messages (e.g. `\"String\"`, `\"Number\"`).\n */\n content: string;\n /**\n * Converts a raw CLI string into `Value`.\n *\n * @param input - Raw string from the command line.\n * @returns The decoded value.\n * @throws {@link TypoError} on invalid input.\n */\n decoder(input: string): Value;\n};\n\n/**\n * Decodes `\"true\"` / `\"yes\"` → `true` and `\"false\"` / `\"no\"` → `false` (case-insensitive).\n * Used internally by {@link optionFlag} for the `--flag=<value>` syntax.\n *\n * @example\n * ```ts\n * typeBoolean.decoder(\"yes\") // → true\n * typeBoolean.decoder(\"false\") // → false\n * typeBoolean.decoder(\"1\") // throws TypoError\n * ```\n */\nexport const typeBoolean: Type<boolean> = {\n content: \"Boolean\",\n decoder(input: string) {\n const lower = input.toLowerCase();\n if (lower === \"true\" || lower === \"yes\") {\n return true;\n }\n if (lower === \"false\" || lower === \"no\") {\n return false;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Invalid value: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n },\n};\n\n/**\n * Parses a date/time string via `Date.parse` into a `Date` object.\n * Accepts any format supported by `Date.parse`, including ISO 8601.\n *\n * @example\n * ```ts\n * typeDate.decoder(\"2024-01-15\") // → Date object for 2024-01-15\n * typeDate.decoder(\"2024-01-15T13:45:30Z\") // → Date object for 2024-01-15 13:45:30 UTC\n * typeDate.decoder(\"not a date\") // throws TypoError\n * ```\n */\nexport const typeDate: Type<Date> = {\n content: \"Date\",\n decoder(input: string) {\n try {\n const timestampMs = Date.parse(input);\n if (isNaN(timestampMs)) {\n throw new Error();\n }\n return new Date(timestampMs);\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Not a valid ISO_8601: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n};\n\n/**\n * Parses a string into a `number` via `Number()`.\n * Accepts integers, floats, and scientific notation; `NaN` throws a {@link TypoError}.\n *\n * @example\n * ```ts\n * typeNumber.decoder(\"3.14\") // → 3.14\n * typeNumber.decoder(\"-1\") // → -1\n * typeNumber.decoder(\"hello\") // throws TypoError\n * ```\n */\nexport const typeNumber: Type<number> = {\n content: \"Number\",\n decoder(input: string) {\n try {\n const parsed = Number(input);\n if (isNaN(parsed)) {\n throw new Error();\n }\n return parsed;\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Unable to parse: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n};\n\n/**\n * Parses an integer string into a `bigint` via `BigInt()`.\n * Floats and non-numeric strings throw a {@link TypoError}.\n *\n * @example\n * ```ts\n * typeInteger.decoder(\"42\") // → 42n\n * typeInteger.decoder(\"3.14\") // throws TypoError\n * typeInteger.decoder(\"abc\") // throws TypoError\n * ```\n */\nexport const typeInteger: Type<bigint> = {\n content: \"Integer\",\n decoder(input: string) {\n try {\n return BigInt(input);\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Unable to parse: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n};\n\n/**\n * Parses an absolute URL string into a `URL` object.\n * Relative or malformed URLs throw a {@link TypoError}.\n *\n * @example\n * ```ts\n * typeUrl.decoder(\"https://example.com\") // → URL { href: \"https://example.com/\", ... }\n * typeUrl.decoder(\"not-a-url\") // throws TypoError\n * ```\n */\nexport const typeUrl: Type<URL> = {\n content: \"Url\",\n decoder(input: string) {\n try {\n return new URL(input);\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Unable to parse: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n};\n\n/**\n * Identity decoder — passes the raw string through unchanged.\n *\n * @example\n * ```ts\n * typeString.decoder(\"hello\") // → \"hello\"\n * typeString.decoder(\"\") // → \"\"\n * ```\n */\nexport const typeString: Type<string> = {\n content: \"String\",\n decoder(input: string) {\n return input;\n },\n};\n\n/**\n * Creates a {@link Type} by chaining `before`'s decoder with an `after` transformation.\n * `before` errors are prefixed with `\"from: <content>\"` for traceability.\n *\n * @typeParam Before - Intermediate type from `before.decoder`.\n * @typeParam After - Final type from `after.decoder`.\n *\n * @param before - Base decoder for the raw string.\n * @param after - Transformation applied to the decoded value.\n * @param after.content - Name for the resulting type (shown in errors).\n * @param after.decoder - Converts a `Before` value to `After`.\n * @returns A {@link Type}`<After>`.\n *\n * @example\n * ```ts\n * const typePort = typeMapped(typeNumber, {\n * content: \"Port\",\n * decoder: (n) => {\n * if (n < 1 || n > 65535) throw new Error(\"Out of range\");\n * return n;\n * },\n * });\n * // \"--port 8080\" → 8080\n * // \"--port 99999\" → TypoError: --port: <PORT>: Port: Out of range\n * ```\n */\nexport function typeMapped<Before, After>(\n before: Type<Before>,\n after: { content: string; decoder: (value: Before) => After },\n): Type<After> {\n return {\n content: after.content,\n decoder: (input: string) => {\n return after.decoder(\n TypoError.tryWithContext(\n () => before.decoder(input),\n () =>\n new TypoText(\n new TypoString(\"from: \"),\n new TypoString(before.content, typoStyleLogic),\n ),\n ),\n );\n },\n };\n}\n\n/**\n * Creates a {@link Type}`<string>` accepting only a fixed set of string values.\n * Out-of-set inputs throw a {@link TypoError} listing up to 5 valid options.\n *\n * @param content - Name shown in help and errors (e.g. `\"Environment\"`).\n * @param values - Ordered list of accepted values.\n * @returns A {@link Type}`<string>`.\n *\n * @example\n * ```ts\n * const typeEnv = typeOneOf(\"Environment\", [\"dev\", \"staging\", \"prod\"]);\n * typeEnv.decoder(\"prod\") // → \"prod\"\n * typeEnv.decoder(\"unknown\") // throws TypoError: Invalid value: \"unknown\" (expected one of: \"dev\" | \"staging\" | \"prod\")\n * ```\n */\nexport function typeOneOf<const Value extends string>(\n content: string,\n values: Array<Value>,\n): Type<Value> {\n return {\n content: content,\n decoder(input: string) {\n for (const value of values) {\n if (input === value) {\n return value;\n }\n }\n const valuesPreview = [];\n for (const value of values) {\n if (valuesPreview.length >= 5) {\n valuesPreview.push(new TypoString(`...`));\n break;\n }\n if (valuesPreview.length > 0) {\n valuesPreview.push(new TypoString(` | `));\n }\n valuesPreview.push(new TypoString(`\"${value}\"`, typoStyleQuote));\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Invalid value: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n new TypoString(` (expected one of: `),\n ...valuesPreview,\n new TypoString(`)`),\n ),\n );\n },\n };\n}\n\n/**\n * Splits a delimited string into a fixed-length typed tuple.\n * Each part is decoded by the corresponding element type; wrong count or decode failure throws {@link TypoError}.\n *\n * @typeParam Elements - Tuple of decoded value types (inferred from `elementTypes`).\n *\n * @param elementTypes - One {@link Type} per tuple element, in order.\n * @param separator - Delimiter (default `\",\"`).\n * @returns A {@link Type}`<Elements>`.\n *\n * @example\n * ```ts\n * const typePoint = typeTuple([typeNumber, typeNumber]);\n * typePoint.decoder(\"3.14,2.71\") // → [3.14, 2.71]\n * typePoint.decoder(\"1,2,3\") // → [1, 2]\n * typePoint.decoder(\"x,2\") // throws TypoError: at 0: Number: Unable to parse: \"x\"\n * ```\n */\nexport function typeTuple<const Elements extends Array<any>>(\n elementTypes: { [K in keyof Elements]: Type<Elements[K]> },\n separator: string = \",\",\n): Type<Elements> {\n return {\n content: elementTypes\n .map((elementType) => elementType.content)\n .join(separator),\n decoder(value: string) {\n const splits = value.split(separator, elementTypes.length);\n if (splits.length !== elementTypes.length) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Found ${splits.length} splits: `),\n new TypoString(`Expected ${elementTypes.length} splits from: `),\n new TypoString(`\"${value}\"`, typoStyleQuote),\n ),\n );\n }\n return splits.map((split, index) => {\n const elementType = elementTypes[index]!;\n return TypoError.tryWithContext(\n () => elementType.decoder(split),\n () =>\n new TypoText(\n new TypoString(`at ${index}: `),\n new TypoString(elementType.content, typoStyleLogic),\n ),\n );\n }) as Elements;\n },\n };\n}\n\n/**\n * Splits a delimited string into a variable-length typed array.\n * Each part is decoded by `elementType`; failed decodes throw {@link TypoError}.\n * Note: splitting an empty string yields one empty element — prefer {@link optionRepeatable} for a zero-default.\n *\n * @typeParam Value - Element type produced by `elementType.decoder`.\n *\n * @param elementType - Decoder applied to each element.\n * @param separator - Delimiter (default `\",\"`).\n * @returns A {@link Type}`<Array<Value>>`.\n *\n * @example\n * ```ts\n * const typeNumbers = typeList(typeNumber);\n * typeNumbers.decoder(\"1,2,3\") // → [1, 2, 3]\n * typeNumbers.decoder(\"1,x,3\") // throws TypoError: at 1: Number: Unable to parse: \"x\"\n *\n * const typePaths = typeList(typeString, \":\");\n * typePaths.decoder(\"/usr/bin:/usr/local/bin\") // → [\"/usr/bin\", \"/usr/local/bin\"]\n * ```\n */\nexport function typeList<Value>(\n elementType: Type<Value>,\n separator: string = \",\",\n): Type<Array<Value>> {\n return {\n content: `${elementType.content}[${separator}${elementType.content}]...`,\n decoder(input: string) {\n const splits = input.split(separator);\n return splits.map((split, index) =>\n TypoError.tryWithContext(\n () => elementType.decoder(split),\n () =>\n new TypoText(\n new TypoString(`at ${index}: `),\n new TypoString(elementType.content, typoStyleLogic),\n ),\n ),\n );\n },\n };\n}\n","import { ReaderArgs as ReaderOptions } from \"./Reader\";\nimport { Type, typeBoolean } from \"./Type\";\nimport {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleLogic,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\n\n/**\n * A CLI option (flag or valued) with its parsing and usage-generation logic.\n *\n * Created with {@link optionFlag}, {@link optionSingleValue}, or\n * {@link optionRepeatable} and passed via the `options` map of {@link operation}.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type Option<Value> = {\n /**\n * Returns metadata used to render the `Options:` section of help.\n */\n generateUsage(): OptionUsage;\n /**\n * Registers the option on `readerOptions` and returns an {@link OptionDecoder}.\n */\n registerAndMakeDecoder(readerOptions: ReaderOptions): OptionDecoder<Value>;\n};\n\n/**\n * Produced by {@link Option.registerAndMakeDecoder}.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type OptionDecoder<Value> = {\n /**\n * Returns the decoded option value.\n *\n * @throws {@link TypoError} if decoding failed.\n */\n getAndDecodeValue(): Value;\n};\n\n/**\n * Human-readable metadata for a single option, used to render the `Options:` section\n * of the help output produced by {@link usageToStyledLines}.\n */\nexport type OptionUsage = {\n /**\n * Long-form name without `--` (e.g. `\"verbose\"`).\n */\n long: Lowercase<string>;\n /**\n * Short-form name without `-` (e.g. `\"v\"`).\n */\n short: string | undefined;\n /**\n * Help text in usage.\n */\n description: string | undefined;\n /**\n * Short note shown in parentheses.\n */\n hint: string | undefined;\n /**\n * Value placeholder in help (e.g. `\"<FILE>\"`). `undefined` for flags.\n */\n label: Uppercase<string> | undefined;\n};\n\n/**\n * Creates a boolean flag option (`--verbose`, optionally `--flag=no`).\n *\n * Parsing: absent → `false`; `--flag` / `--flag=yes` → `true`; `--flag=no` → `false`;\n * specified more than once → {@link TypoError}.\n *\n * @param definition - Flag configuration.\n * @param definition.long - Long-form name (without `--`).\n * @param definition.short - Short-form name (without `-`).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.aliases - Additional names.\n * @param definition.default - Default when absent. Defaults to `() => false`.\n * @returns An {@link Option}`<boolean>`.\n *\n * @example\n * ```ts\n * const verboseFlag = optionFlag({\n * long: \"verbose\",\n * short: \"v\",\n * description: \"Enable verbose output\",\n * });\n * ```\n */\nexport function optionFlag(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n default?: () => boolean;\n}): Option<boolean> {\n const label = `<${typeBoolean.content.toUpperCase()}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: undefined,\n };\n },\n registerAndMakeDecoder(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: false,\n });\n return {\n getAndDecodeValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n try {\n return definition.default ? definition.default() : false;\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to get default value`),\n ),\n error,\n );\n }\n }\n return decodeValue({\n long: definition.long,\n short: definition.short,\n label,\n type: typeBoolean,\n input: optionValue,\n });\n },\n };\n },\n };\n}\n\n/**\n * Creates an option that accepts exactly one value (e.g. `--output dist/`).\n *\n * Parsing: absent → `default()`; once → decoded with `type`; more than once → {@link TypoError}.\n * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.\n *\n * @typeParam Value - Type produced by the decoder.\n *\n * @param definition - Option configuration.\n * @param definition.long - Long-form name (without `--`).\n * @param definition.short - Short-form name (without `-`).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.aliases - Additional names.\n * @param definition.label - Value placeholder in help. Defaults to uppercased `type.content`.\n * @param definition.type - Decoder for the raw string value.\n * @param definition.default - Default when absent. Throw to make the option required.\n * @returns An {@link Option}`<Value>`.\n *\n * @example\n * ```ts\n * const outputOption = optionSingleValue({\n * long: \"output\",\n * short: \"o\",\n * type: typeString,\n * label: \"PATH\",\n * description: \"Output directory\",\n * default: () => \"dist/\",\n * });\n * ```\n */\nexport function optionSingleValue<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Option<Value> {\n const label = `<${definition.label ?? definition.type.content.toUpperCase()}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n registerAndMakeDecoder(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getAndDecodeValue() {\n const optionValues = readerOptions.getOptionValues(key);\n if (optionValues.length > 1) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Requires a single value, but got multiple`),\n ),\n );\n }\n const optionValue = optionValues[0];\n if (optionValue === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${definition.long}`, typoStyleConstants),\n new TypoString(`: Failed to get default value`),\n ),\n error,\n );\n }\n }\n return decodeValue({\n long: definition.long,\n short: definition.short,\n label,\n type: definition.type,\n input: optionValue,\n });\n },\n };\n },\n };\n}\n\n/**\n * Creates an option that collects every occurrence into an array (e.g. `--file a.ts --file b.ts`).\n *\n * Parsing: absent → `[]`; N occurrences → array of N decoded values in order.\n * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.\n *\n * @typeParam Value - Type produced by the decoder for each occurrence.\n *\n * @param definition - Option configuration.\n * @param definition.long - Long-form name (without `--`).\n * @param definition.short - Short-form name (without `-`).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.aliases - Additional names.\n * @param definition.label - Value placeholder in help. Defaults to uppercased `type.content`.\n * @param definition.type - Decoder applied to each raw string value.\n * @returns An {@link Option}`<Array<Value>>`.\n *\n * @example\n * ```ts\n * const filesOption = optionRepeatable({\n * long: \"file\",\n * short: \"f\",\n * type: typeString,\n * label: \"PATH\",\n * description: \"Input file (may be repeated)\",\n * });\n * // Usage: my-cli --file a.ts --file b.ts → [\"a.ts\", \"b.ts\"]\n * ```\n */\nexport function optionRepeatable<Value>(definition: {\n long: Lowercase<string>;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Option<Array<Value>> {\n const label = `<${definition.label ?? definition.type.content.toUpperCase()}>`;\n return {\n generateUsage() {\n // TODO - showcase that it can be repeated ?\n return {\n description: definition.description,\n hint: definition.hint,\n long: definition.long,\n short: definition.short,\n label: label as Uppercase<string>,\n };\n },\n registerAndMakeDecoder(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n ...definition,\n valued: true,\n });\n return {\n getAndDecodeValue() {\n const optionValues = readerOptions.getOptionValues(key);\n return optionValues.map((optionValue) =>\n decodeValue({\n long: definition.long,\n short: definition.short,\n label,\n type: definition.type,\n input: optionValue,\n }),\n );\n },\n };\n },\n };\n}\n\nfunction decodeValue<Value>(params: {\n long: string;\n short: string | undefined;\n label: string;\n type: Type<Value>;\n input: string;\n}): Value {\n return TypoError.tryWithContext(\n () => params.type.decoder(params.input),\n () => {\n const text = new TypoText();\n if (params.short) {\n text.pushString(new TypoString(`-${params.short}`, typoStyleConstants));\n text.pushString(new TypoString(`, `));\n }\n text.pushString(new TypoString(`--${params.long}`, typoStyleConstants));\n text.pushString(new TypoString(`: `));\n text.pushString(new TypoString(params.label, typoStyleUserInput));\n text.pushString(new TypoString(`: `));\n text.pushString(new TypoString(params.type.content, typoStyleLogic));\n return text;\n },\n );\n}\n\nfunction registerOption(\n readerOptions: ReaderOptions,\n definition: {\n long: Lowercase<string>;\n short?: string;\n aliases?: { longs?: Array<Lowercase<string>>; shorts?: Array<string> };\n valued: boolean;\n },\n) {\n const { long, short, aliases, valued } = definition;\n const longs = long ? [long] : [];\n if (aliases?.longs) {\n longs.push(...aliases?.longs);\n }\n const shorts = short ? [short] : [];\n if (aliases?.shorts) {\n shorts.push(...aliases?.shorts);\n }\n return readerOptions.registerOption({ longs, shorts, valued });\n}\n","import { ReaderPositionals } from \"./Reader\";\nimport { Type } from \"./Type\";\nimport {\n TypoError,\n TypoString,\n typoStyleLogic,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\n\n/**\n * A bare (non-option) positional argument with its parsing and usage-generation logic.\n *\n * Created with {@link positionalRequired}, {@link positionalOptional}, or\n * {@link positionalVariadics} and passed via the `positionals` array of\n * {@link operation}, consumed in declaration order.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type Positional<Value> = {\n /**\n * Returns metadata used to render the `Positionals:` section of help.\n */\n generateUsage(): PositionalUsage;\n /**\n * Consumes the next positional token from `readerPositionals`.\n * Returns a decoder that produces the final value.\n */\n consumeAndMakeDecoder(\n readerPositionals: ReaderPositionals,\n ): PositionalDecoder<Value>;\n};\n\n/**\n * Produced by {@link Positional.consumeAndMakeDecoder}.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type PositionalDecoder<Value> = {\n /**\n * Returns the decoded positional value.\n *\n * @throws {@link TypoError} if decoding failed.\n */\n decodeValue(): Value;\n};\n\n/**\n * Human-readable metadata for a single positional argument, used to render the\n * `Positionals:` section of the help output produced by {@link usageToStyledLines}.\n */\nexport type PositionalUsage = {\n /**\n * Help text.\n */\n description: string | undefined;\n /**\n * Short note shown in parentheses.\n */\n hint: string | undefined;\n /**\n * Placeholder label shown in the usage line and the `Positionals:` section.\n * Required: `<NAME>`, optional: `[NAME]`, variadic: `[NAME]...`.\n */\n label: Uppercase<string>;\n};\n\n/**\n * Creates a required positional — missing token throws {@link TypoError}.\n * Label defaults to uppercased `type.content` in angle brackets (e.g. `<STRING>`).\n *\n * @typeParam Value - Type produced by the decoder.\n *\n * @param definition - Positional configuration.\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.label - Label without brackets; defaults to uppercased `type.content`.\n * @param definition.type - Decoder for the raw token.\n * @returns A {@link Positional}`<Value>`.\n *\n * @example\n * ```ts\n * const namePositional = positionalRequired({\n * type: typeString,\n * label: \"NAME\",\n * description: \"The name to greet\",\n * });\n * // Parses: my-cli Alice → \"Alice\"\n * ```\n */\nexport function positionalRequired<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Value> {\n const label = `<${definition.label ?? definition.type.content.toUpperCase()}>`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumeAndMakeDecoder(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n return {\n decodeValue() {\n return decodeValue(label, definition.type, positional);\n },\n };\n },\n };\n}\n\n/**\n * Creates an optional positional — absent token falls back to `default()`.\n * Label defaults to uppercased `type.content` in square brackets (e.g. `[STRING]`).\n *\n * @typeParam Value - Type produced by the decoder (or the default).\n *\n * @param definition - Positional configuration.\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.label - Label without brackets; defaults to uppercased `type.content`.\n * @param definition.type - Decoder for the raw token.\n * @param definition.default - Value when absent. Throw to make it required.\n * @returns A {@link Positional}`<Value>`.\n *\n * @example\n * ```ts\n * const greeteePositional = positionalOptional({\n * type: typeString,\n * label: \"NAME\",\n * description: \"Name to greet (default: world)\",\n * default: () => \"world\",\n * });\n * // my-cli → \"world\"\n * // my-cli Alice → \"Alice\"\n * ```\n */\nexport function positionalOptional<Value>(definition: {\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n default: () => Value;\n}): Positional<Value> {\n const label = `[${definition.label ?? definition.type.content.toUpperCase()}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: label as Uppercase<string>,\n };\n },\n consumeAndMakeDecoder(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n return {\n decodeValue() {\n if (positional === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Failed to get default value`),\n ),\n error,\n );\n }\n }\n return decodeValue(label, definition.type, positional);\n },\n };\n },\n };\n}\n\n/**\n * Creates a variadic positional that collects zero or more remaining tokens into an array.\n * Stops at `endDelimiter` (consumed, not included). Label: `[TYPE]...` notation.\n *\n * @typeParam Value - Type produced by the decoder for each token.\n *\n * @param definition - Positional configuration.\n * @param definition.endDelimiter - Sentinel token that stops collection (consumed, not included).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.label - Label without brackets; defaults to uppercased `type.content`.\n * @param definition.type - Decoder applied to each token.\n * @returns A {@link Positional}`<Array<Value>>`.\n *\n * @example\n * ```ts\n * const filesPositional = positionalVariadics({\n * type: typeString,\n * label: \"FILE\",\n * description: \"Files to process\",\n * });\n * // my-cli a.ts b.ts c.ts → [\"a.ts\", \"b.ts\", \"c.ts\"]\n * // my-cli → []\n * ```\n */\nexport function positionalVariadics<Value>(definition: {\n endDelimiter?: string;\n description?: string;\n hint?: string;\n label?: Uppercase<string>;\n type: Type<Value>;\n}): Positional<Array<Value>> {\n const label = `[${definition.label ?? definition.type.content.toUpperCase()}]`;\n return {\n generateUsage() {\n return {\n description: definition.description,\n hint: definition.hint,\n label: (`${label}...` +\n (definition.endDelimiter\n ? `[\"${definition.endDelimiter}\"]`\n : \"\")) as Uppercase<string>,\n };\n },\n consumeAndMakeDecoder(readerPositionals: ReaderPositionals) {\n const positionals = new Array<string>();\n while (true) {\n const positional = readerPositionals.consumePositional();\n if (\n positional === undefined ||\n positional === definition.endDelimiter\n ) {\n break;\n }\n positionals.push(positional);\n }\n return {\n decodeValue() {\n return positionals.map((positional) => {\n return decodeValue(label, definition.type, positional);\n });\n },\n };\n },\n };\n}\n\nfunction decodeValue<Value>(\n label: string,\n type: Type<Value>,\n input: string,\n): Value {\n return TypoError.tryWithContext(\n () => type.decoder(input),\n () =>\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: `),\n new TypoString(type.content, typoStyleLogic),\n ),\n );\n}\n","import {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleQuote,\n TypoText,\n} from \"./Typo\";\n\n/**\n * Opaque key identifying a registered option within a {@link ReaderArgs} instance.\n * Returned by {@link ReaderArgs.registerOption}; passed to {@link ReaderArgs.getOptionValues}.\n */\nexport type ReaderOptionKey = (string | { __brand: \"ReaderOptionKey\" }) & {\n __brand: \"ReaderOptionKey\";\n};\n\n/**\n * Option registration and query interface, implemented by {@link ReaderArgs}.\n * Exposed separately from {@link ReaderPositionals} so parsers depend only on what they need.\n */\nexport type ReaderOptions = {\n /**\n * Registers an option so the parser can recognise it.\n *\n * @param definition.longs - Long-form names (without `--`).\n * @param definition.shorts - Short-form names (without `-`).\n * @param definition.valued - `true` if the option takes a value; `false` for flags.\n * @returns A {@link ReaderOptionKey} for later retrieval.\n * @throws `Error` if a name is already registered or short names overlap.\n */\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }): ReaderOptionKey;\n /**\n * Returns all values collected for the option identified by `key`.\n *\n * @param key - Key from {@link ReaderOptions.registerOption}.\n * @returns Raw string values, one per occurrence; empty if never provided.\n * @throws `Error` if `key` was not registered.\n */\n getOptionValues(key: ReaderOptionKey): Array<string>;\n};\n\n/**\n * Positional token consumption interface, implemented by {@link ReaderArgs}.\n */\nexport type ReaderPositionals = {\n /**\n * Returns the next positional token, parsing intervening options as side-effects.\n *\n * @returns The next positional, or `undefined` when exhausted.\n * @throws {@link TypoError} on an unrecognised option.\n */\n consumePositional(): string | undefined;\n};\n\n/**\n * Core argument parser: converts raw CLI tokens into named options and positionals.\n * Options must be registered before {@link ReaderArgs.consumePositional} is called.\n *\n * Supported syntax: `--name`, `--name value`, `--name=value`,\n * `-n`, `-n value`, `-nvalue`, `-abc` (stacked), `--` (end-of-options).\n *\n * Created internally by {@link runAndExit}; exposed for advanced / custom runners.\n */\nexport class ReaderArgs {\n #args: ReadonlyArray<string>;\n #parsedIndex: number;\n #parsedDouble: boolean;\n #keyByLong: Map<string, ReaderOptionKey>;\n #keyByShort: Map<string, ReaderOptionKey>;\n #valuedByKey: Map<ReaderOptionKey, boolean>;\n #resultByKey: Map<ReaderOptionKey, Array<string>>;\n\n /**\n * @param args - Raw CLI tokens (e.g. `process.argv.slice(2)`). Not mutated.\n */\n constructor(args: ReadonlyArray<string>) {\n this.#args = args;\n this.#parsedIndex = 0;\n this.#parsedDouble = false;\n this.#keyByLong = new Map();\n this.#keyByShort = new Map();\n this.#valuedByKey = new Map();\n this.#resultByKey = new Map();\n }\n\n /**\n * Registers an option; all `longs` and `shorts` share the same key.\n * Short names support stacking (e.g. `-abc`) and inline values (e.g. `-nvalue`),\n * but must not be prefixes of one another.\n *\n * @param definition.longs - Long-form names (without `--`).\n * @param definition.shorts - Short-form names (without `-`).\n * @param definition.valued - `true` if the option takes a value; `false` for flags.\n * @returns A {@link ReaderOptionKey} for {@link ReaderArgs.getOptionValues}.\n * @throws `Error` if any name is already registered or short names overlap.\n */\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n valued: boolean;\n }) {\n const key = [\n ...definition.longs.map((long) => `--${long}`),\n ...definition.shorts.map((short) => `-${short}`),\n ].join(\", \") as ReaderOptionKey;\n for (const long of definition.longs) {\n if (!this.#isValidOptionName(long)) {\n throw new Error(`Invalid option name: --${long}`);\n }\n if (this.#keyByLong.has(long)) {\n throw new Error(`Option already registered: --${long}`);\n }\n }\n for (const short of definition.shorts) {\n if (!this.#isValidOptionName(short)) {\n throw new Error(`Invalid option name: -${short}`);\n }\n if (this.#keyByShort.has(short)) {\n throw new Error(`Option already registered: -${short}`);\n }\n for (let i = 0; i < short.length; i++) {\n const shortSlice = short.slice(0, i);\n if (this.#keyByShort.has(shortSlice)) {\n throw new Error(\n `Option -${short} overlap with shorter option: -${shortSlice}`,\n );\n }\n }\n for (const shortOther of this.#keyByShort.keys()) {\n if (shortOther.startsWith(short)) {\n throw new Error(\n `Option -${short} overlap with longer option: -${shortOther}`,\n );\n }\n }\n }\n for (const long of definition.longs) {\n this.#keyByLong.set(long, key);\n }\n for (const short of definition.shorts) {\n this.#keyByShort.set(short, key);\n }\n this.#valuedByKey.set(key, definition.valued);\n this.#resultByKey.set(key, new Array<string>());\n return key;\n }\n\n /**\n * Returns all values collected for the option key.\n *\n * @param key - Key from {@link ReaderArgs.registerOption}.\n * @returns String values, one per occurrence.\n * @throws `Error` if `key` was not registered.\n */\n getOptionValues(key: ReaderOptionKey): Array<string> {\n const optionResult = this.#resultByKey.get(key);\n if (optionResult === undefined) {\n throw new Error(`Unregistered option: ${key}`);\n }\n return optionResult;\n }\n\n /**\n * Returns the next bare positional token.\n * Parse intervening options as side-effects.\n * All tokens after `--` are treated as positionals.\n *\n * @returns The next positional, or `undefined` when exhausted.\n * @throws {@link TypoError} on an unrecognised option.\n */\n consumePositional(): string | undefined {\n while (true) {\n const arg = this.#consumeArg();\n if (arg === null) {\n return undefined;\n }\n if (this.#processedAsPositional(arg)) {\n return arg;\n }\n }\n }\n\n #consumeArg(): string | null {\n const arg = this.#args[this.#parsedIndex];\n if (arg === undefined) {\n return null;\n }\n this.#parsedIndex++;\n if (!this.#parsedDouble) {\n if (arg === \"--\") {\n this.#parsedDouble = true;\n return this.#consumeArg();\n }\n }\n return arg;\n }\n\n #processedAsPositional(arg: string): boolean {\n if (this.#parsedDouble) {\n return true;\n }\n if (arg.startsWith(\"--\")) {\n const valueIndexStart = arg.indexOf(\"=\");\n if (valueIndexStart === -1) {\n this.#consumeOptionLong(arg.slice(2), null);\n } else {\n this.#consumeOptionLong(\n arg.slice(2, valueIndexStart),\n arg.slice(valueIndexStart + 1),\n );\n }\n return false;\n }\n if (arg.startsWith(\"-\")) {\n let shortIndexStart = 1;\n let shortIndexEnd = 2;\n while (shortIndexEnd <= arg.length) {\n const result = this.#tryConsumeOptionShort(\n arg.slice(shortIndexStart, shortIndexEnd),\n arg.slice(shortIndexEnd),\n );\n if (result === true) {\n return false;\n }\n if (result === false) {\n shortIndexStart = shortIndexEnd;\n }\n shortIndexEnd++;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`-${arg.slice(shortIndexStart)}`, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n return true;\n }\n\n #consumeOptionLong(long: string, direct: string | null): void {\n const constant = `--${long}`;\n const key = this.#keyByLong.get(long);\n if (key !== undefined) {\n if (direct !== null) {\n return this.#acknowledgeOption(key, direct);\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n return this.#acknowledgeOption(key, this.#consumeOptionValue(constant));\n }\n return this.#acknowledgeOption(key, \"true\");\n }\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Unexpected unknown option`),\n ),\n );\n }\n\n #tryConsumeOptionShort(short: string, rest: string): boolean | null {\n const key = this.#keyByShort.get(short);\n if (key !== undefined) {\n if (rest.startsWith(\"=\")) {\n this.#acknowledgeOption(key, rest.slice(1));\n return true;\n }\n const valued = this.#valuedByKey.get(key);\n if (valued) {\n if (rest === \"\") {\n this.#acknowledgeOption(key, this.#consumeOptionValue(`-${short}`));\n } else {\n this.#acknowledgeOption(key, rest);\n }\n return true;\n }\n this.#acknowledgeOption(key, \"true\");\n return rest === \"\";\n }\n return null;\n }\n\n #consumeOptionValue(constant: string) {\n const arg = this.#consumeArg();\n if (arg === null) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got end of input`),\n ),\n );\n }\n if (this.#parsedDouble) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value before `),\n new TypoString(`\"--\"`, typoStyleQuote),\n ),\n );\n }\n // TODO - is that weird, could a valid value start with dash ?\n if (arg.startsWith(\"-\")) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got: `),\n new TypoString(`\"${arg}\"`, typoStyleQuote),\n ),\n );\n }\n return arg;\n }\n\n #acknowledgeOption(key: ReaderOptionKey, value: string) {\n this.getOptionValues(key).push(value);\n }\n\n #isValidOptionName(name: string): boolean {\n return name.length > 0 && !name.includes(\"=\");\n }\n}\n","import { CommandUsage } from \"./Command\";\nimport {\n TypoGrid,\n TypoString,\n typoStyleConstants,\n typoStyleLogic,\n typoStyleRegularStrong,\n typoStyleRegularWeaker,\n typoStyleTitle,\n typoStyleUserInput,\n TypoSupport,\n TypoText,\n} from \"./Typo\";\n\n/**\n * Converts a {@link CommandUsage} model into an array of styled lines ready to be\n * joined with `\"\\n\"` and printed to the terminal.\n *\n * The output format is:\n * ```\n * Usage: <cliName> [segments...]\n *\n * <description> (<hint>)\n * <detail lines...>\n *\n * Positionals:\n * <LABEL> <description> (<hint>)\n *\n * Subcommands:\n * <name> <description> (<hint>)\n *\n * Options:\n * -s, --long <LABEL> <description> (<hint>)\n *\n * Examples:\n * <description>\n * <command line>\n *\n * ```\n * Sections that have no entries are omitted. The trailing empty line is always included.\n *\n * Column alignment within each section is handled by {@link TypoGrid}: the widest entry\n * in each column sets the width for the entire section.\n *\n * @param params.cliName - Program name for the usage line.\n * @param params.commandUsage - From {@link CommandDecoder.generateUsage}.\n * @param params.typoSupport - Rendering mode.\n * @returns One string per output line; trailing empty string for the blank line at the end.\n *\n * @example\n * ```ts\n * const lines = usageToStyledLines({\n * cliName: \"my-cli\",\n * commandUsage: commandDecoder.generateUsage(),\n * typoSupport: TypoSupport.tty(),\n * });\n * process.stdout.write(lines.join(\"\\n\"));\n * ```\n */\nexport function usageToStyledLines(params: {\n cliName: Lowercase<string>;\n commandUsage: CommandUsage;\n typoSupport: TypoSupport;\n}) {\n const { cliName, commandUsage, typoSupport } = params;\n\n const lines = new Array<string>();\n\n const segments = [\n textUsageHero(\"Usage:\").computeStyledString(typoSupport),\n textConstants(cliName).computeStyledString(typoSupport),\n ].concat(\n commandUsage.segments.map((segment) => {\n if (\"positional\" in segment) {\n return textUserInput(segment.positional).computeStyledString(\n typoSupport,\n );\n }\n if (\"command\" in segment) {\n return textConstants(segment.command).computeStyledString(typoSupport);\n }\n throw new Error(`Unknown segment: ${JSON.stringify(segment)}`);\n }),\n );\n lines.push(segments.join(\" \"));\n\n lines.push(\"\");\n const introText = new TypoText();\n introText.pushString(textUsageText(commandUsage.information.description));\n if (commandUsage.information.hint) {\n introText.pushString(textDelimiter(\" \"));\n introText.pushString(textSubtleInfo(`(${commandUsage.information.hint})`));\n }\n lines.push(introText.computeStyledString(typoSupport));\n for (const detail of commandUsage.information.details ?? []) {\n const detailText = new TypoText();\n detailText.pushString(textSubtleInfo(detail));\n lines.push(detailText.computeStyledString(typoSupport));\n }\n\n if (commandUsage.positionals.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Positionals:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const positionalUsage of commandUsage.positionals) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textUserInput(positionalUsage.label)));\n typoGridRow.push(...createInformationals(positionalUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.subcommands.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Subcommands:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const subcommandUsage of commandUsage.subcommands) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textConstants(subcommandUsage.name)));\n typoGridRow.push(...createInformationals(subcommandUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.options.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Options:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const optionUsage of commandUsage.options) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n if (optionUsage.short) {\n typoGridRow.push(\n new TypoText(\n textConstants(`-${optionUsage.short}`),\n textDelimiter(\", \"),\n ),\n );\n } else {\n typoGridRow.push(new TypoText());\n }\n if (optionUsage.label) {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textDelimiter(\" \"),\n textUserInput(optionUsage.label),\n ),\n );\n } else {\n typoGridRow.push(\n new TypoText(\n textConstants(`--${optionUsage.long}`),\n textSubtleInfo(\"[=no]\"),\n ),\n );\n }\n typoGridRow.push(...createInformationals(optionUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(\n ...typoGrid.computeStyledGrid(typoSupport).map((row) => row.join(\"\")),\n );\n }\n\n if (commandUsage.information.examples) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Examples:\").computeStyledString(typoSupport));\n for (const example of commandUsage.information.examples) {\n const exampleExplanationText = new TypoText();\n exampleExplanationText.pushString(textDelimiter(\" \"));\n exampleExplanationText.pushString(\n textSubtleInfo(`# ${example.explanation}`),\n );\n lines.push(exampleExplanationText.computeStyledString(typoSupport));\n const commandLineText = new TypoText();\n commandLineText.pushString(textDelimiter(\" \"));\n commandLineText.pushString(textConstants(cliName));\n for (const commandArg of example.commandArgs) {\n commandLineText.pushString(textDelimiter(\" \"));\n if (typeof commandArg === \"string\") {\n commandLineText.pushString(commandArg);\n } else if (\"positional\" in commandArg) {\n commandLineText.pushString(textUserInput(commandArg.positional));\n } else if (\"subcommand\" in commandArg) {\n commandLineText.pushString(textConstants(commandArg.subcommand));\n } else if (\"option\" in commandArg) {\n const option = commandArg.option;\n if (\"short\" in option) {\n commandLineText.pushString(textConstants(`-${option.short}`));\n } else {\n commandLineText.pushString(textConstants(`--${option.long}`));\n }\n if (option.value !== undefined) {\n commandLineText.pushString(textSubtleInfo(\"=\"));\n commandLineText.pushString(textUserInput(option.value));\n }\n }\n }\n lines.push(commandLineText.computeStyledString(typoSupport));\n }\n }\n\n lines.push(\"\");\n return lines;\n}\n\nfunction createInformationals(usage: {\n description: string | undefined;\n hint: string | undefined;\n}): Array<TypoText> {\n const informationals = [];\n if (usage.description) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textUsefulInfo(usage.description));\n }\n if (usage.hint) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textSubtleInfo(`(${usage.hint})`));\n }\n if (informationals.length > 0) {\n return [new TypoText(textDelimiter(\" \"), ...informationals)];\n }\n return [];\n}\n\nfunction textUsageHero(value: string): TypoString {\n return new TypoString(value, typoStyleLogic);\n}\n\nfunction textUsageText(value: string): TypoString {\n return new TypoString(value, typoStyleRegularStrong);\n}\n\nfunction textUsefulInfo(value: string): TypoString {\n return new TypoString(value);\n}\n\nfunction textBlockTitle(value: string): TypoString {\n return new TypoString(value, typoStyleTitle);\n}\n\nfunction textSubtleInfo(value: string): TypoString {\n return new TypoString(value, typoStyleRegularWeaker);\n}\n\nfunction textConstants(value: string): TypoString {\n return new TypoString(value, typoStyleConstants);\n}\n\nfunction textUserInput(value: string): TypoString {\n return new TypoString(value, typoStyleUserInput);\n}\n\nfunction textDelimiter(value: string): TypoString {\n return new TypoString(value);\n}\n","import { Command, CommandDecoder } from \"./Command\";\nimport { ReaderArgs } from \"./Reader\";\nimport { TypoSupport } from \"./Typo\";\nimport { usageToStyledLines } from \"./Usage\";\n\n/**\n * Main entry point: parses CLI arguments, executes the matched command, and exits.\n * Handles `--help`, `--version`, usage-on-error, and exit codes.\n *\n * Exit codes: `0` on success / `--help` / `--version`; `1` on parse or execution error.\n *\n * @typeParam Context - Passed unchanged to the command handler; use to inject dependencies.\n *\n * @param cliName - Program name used in usage and `--version` output.\n * @param cliArgs - Raw arguments, typically `process.argv.slice(2)`.\n * @param context - Forwarded to the command handler, injected dependencies.\n * @param command - Root {@link Command}.\n * @param options - Optional runner configuration.\n * @param options.useTtyColors - Color mode: `true` (always), `false` (never),\n * `\"mock\"` (snapshot-friendly), `undefined` (auto-detect from env).\n * @param options.usageOnHelp - Enables `--help` flag (default `true`).\n * @param options.usageOnError - Prints usage to stderr on parse error (default `true`).\n * @param options.buildVersion - Enables `--version`; prints `<cliName> <buildVersion>`.\n * @param options.onError - Custom handler for errors.\n * @param options.onExit - Overrides `process.exit`; useful for testing.\n *\n * @returns `Promise<never>` — always calls `onExit`.\n *\n * @example\n * ```ts\n * import { runAndExit, command, operation, positionalRequired, typeString } from \"cli-kiss\";\n *\n * const greetCommand = command(\n * { description: \"Greet someone\" },\n * operation(\n * { options: {}, positionals: [positionalRequired({ type: typeString, label: \"NAME\" })] },\n * async (_ctx, { positionals: [name] }) => {\n * console.log(`Hello, ${name}!`);\n * },\n * ),\n * );\n *\n * await runAndExit(\"greet\", process.argv.slice(2), undefined, greetCommand, {\n * buildVersion: \"1.0.0\",\n * });\n * ```\n */\nexport async function runAndExit<Context>(\n cliName: Lowercase<string>,\n cliArgs: ReadonlyArray<string>,\n context: Context,\n command: Command<Context, void>,\n options?: {\n useTtyColors?: boolean | undefined | \"mock\";\n usageOnHelp?: boolean | undefined;\n usageOnError?: boolean | undefined;\n buildVersion?: string | undefined;\n onError?: ((error: unknown) => void) | undefined;\n onExit?: ((code: number) => never) | undefined;\n },\n): Promise<never> {\n const readerArgs = new ReaderArgs(cliArgs);\n const usageOnHelp = options?.usageOnHelp ?? true;\n if (usageOnHelp) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"help\"],\n valued: false,\n });\n }\n const buildVersion = options?.buildVersion;\n if (buildVersion) {\n readerArgs.registerOption({\n shorts: [],\n longs: [\"version\"],\n valued: false,\n });\n }\n /*\n // TODO - handle completions ?\n readerArgs.registerFlag({\n key: \"completion\",\n shorts: [],\n longs: [\"completion\"],\n });\n */\n const commandDecoder = command.consumeAndMakeDecoder(readerArgs);\n while (true) {\n try {\n const positional = readerArgs.consumePositional();\n if (positional === undefined) {\n break;\n }\n } catch (_) {}\n }\n const onExit = options?.onExit ?? process.exit;\n const typoSupport =\n options?.useTtyColors === undefined\n ? TypoSupport.inferFromProcess()\n : options.useTtyColors === \"mock\"\n ? TypoSupport.mock()\n : options.useTtyColors\n ? TypoSupport.tty()\n : TypoSupport.none();\n if (usageOnHelp) {\n if (readerArgs.getOptionValues(\"--help\" as any).length > 0) {\n console.log(computeUsageString(cliName, commandDecoder, typoSupport));\n return onExit(0);\n }\n }\n if (buildVersion) {\n if (readerArgs.getOptionValues(\"--version\" as any).length > 0) {\n console.log([cliName, buildVersion].join(\" \"));\n return onExit(0);\n }\n }\n try {\n const commandInterpreter = commandDecoder.decodeAndMakeInterpreter();\n try {\n await commandInterpreter.executeWithContext(context);\n return onExit(0);\n } catch (executionError) {\n handleError(options?.onError, executionError, typoSupport);\n return onExit(1);\n }\n } catch (parsingError) {\n if (options?.usageOnError ?? true) {\n console.error(computeUsageString(cliName, commandDecoder, typoSupport));\n }\n handleError(options?.onError, parsingError, typoSupport);\n return onExit(1);\n }\n}\n\nfunction handleError(\n onError: ((error: unknown) => void) | undefined,\n error: unknown,\n typoSupport: TypoSupport,\n) {\n if (onError !== undefined) {\n onError(error);\n } else {\n console.error(typoSupport.computeStyledErrorMessage(error));\n }\n}\n\nfunction computeUsageString<Context, Result>(\n cliName: Lowercase<string>,\n commandDecoder: CommandDecoder<Context, Result>,\n typoSupport: TypoSupport,\n) {\n return usageToStyledLines({\n cliName,\n commandUsage: commandDecoder.generateUsage(),\n typoSupport,\n }).join(\"\\n\");\n}\n"],"mappings":"m3BAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,gBAAAE,EAAA,cAAAC,EAAA,aAAAC,EAAA,eAAAC,EAAA,gBAAAC,EAAA,aAAAC,EAAA,YAAAC,GAAA,mBAAAC,GAAA,2BAAAC,GAAA,cAAAC,GAAA,eAAAC,GAAA,qBAAAC,GAAA,sBAAAC,GAAA,uBAAAC,GAAA,uBAAAC,GAAA,wBAAAC,GAAA,eAAAC,GAAA,gBAAAC,EAAA,aAAAC,GAAA,gBAAAC,GAAA,aAAAC,GAAA,eAAAC,GAAA,eAAAC,GAAA,cAAAC,GAAA,eAAAC,GAAA,cAAAC,GAAA,YAAAC,GAAA,uBAAAC,EAAA,qBAAAC,GAAA,mBAAAC,EAAA,mBAAAC,EAAA,2BAAAC,GAAA,2BAAAC,GAAA,mBAAAC,EAAA,uBAAAC,EAAA,uBAAAC,KAAA,eAAAC,GAAAtC,IC4DO,IAAMuC,EAA4B,CACvC,QAAS,YACT,KAAM,EACR,EAIaC,EAA4B,CACvC,QAAS,cACT,KAAM,EACR,EAIaC,EAA4B,CACvC,QAAS,aACT,KAAM,EACR,EAKaC,GAA8B,CACzC,QAAS,UACT,KAAM,EACR,EAKaC,EAAgC,CAC3C,QAAS,WACT,KAAM,EACR,EAIaC,EAAgC,CAC3C,QAAS,WACT,KAAM,EACR,EAKaC,GAAoC,CAC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B,QAAQ,MAAMS,GAAmBb,EAASS,EAAgBE,CAAW,CAAC,EAExEK,GAAYZ,GAAS,QAASa,EAAcN,CAAW,EAChDD,EAAO,CAAC,CACjB,CACF,CAEA,SAASM,GACPE,EACAC,EACAR,EACA,CACIO,IAAY,OACdA,EAAQC,CAAK,EAEb,QAAQ,MAAMR,EAAY,0BAA0BQ,CAAK,CAAC,CAE9D,CAEA,SAASN,GACPb,EACAS,EACAE,EACA,CACA,OAAOS,GAAmB,CACxB,QAAApB,EACA,aAAcS,EAAe,cAAc,EAC3C,YAAAE,CACF,CAAC,EAAE,KAAK;AAAA,CAAI,CACd","names":["index_exports","__export","ReaderArgs","TypoError","TypoGrid","TypoString","TypoSupport","TypoText","command","commandChained","commandWithSubcommands","operation","optionFlag","optionRepeatable","optionSingleValue","positionalOptional","positionalRequired","positionalVariadics","runAndExit","typeBoolean","typeDate","typeInteger","typeList","typeMapped","typeNumber","typeOneOf","typeString","typeTuple","typeUrl","typoStyleConstants","typoStyleFailure","typoStyleLogic","typoStyleQuote","typoStyleRegularStrong","typoStyleRegularWeaker","typoStyleTitle","typoStyleUserInput","usageToStyledLines","__toCommonJS","typoStyleTitle","typoStyleLogic","typoStyleQuote","typoStyleFailure","typoStyleConstants","typoStyleUserInput","typoStyleRegularStrong","typoStyleRegularWeaker","_value","_typoStyle","TypoString","value","typoStyle","__privateAdd","__privateSet","__privateGet","typoSupport","_typoStrings","_TypoText","typoParts","typoPart","typoString","typoText","t","length","TypoText","_typoRows","TypoGrid","cells","widths","printableGrid","typoGridRow","typoGridColumnIndex","width","printableGridRow","typoGridCell","printableGridCell","padding","_typoText","_TypoError","currentTypoText","source","thrower","context","error","TypoError","_kind","_TypoSupport","kind","fgColorCode","ttyCodeFgColors","bgColorCode","ttyCodeBgColors","boldCode","ttyCodeBold","dimCode","ttyCodeDim","italicCode","ttyCodeItalic","underlineCode","ttyCodeUnderline","strikethroughCode","ttyCodeStrikethrough","ttyCodeReset","fgColorPart","bgColorPart","boldPart","dimPart","italicPart","underlinePart","TypoSupport","command","information","operation","readerArgs","operationDecoder","endPositional","TypoError","TypoText","TypoString","typoStyleQuote","generateUsageShallow","operationInterpreter","context","error","commandWithSubcommands","subcommands","subcommandName","typoStyleUserInput","subcommandInput","subcommandDecoder","subcommandUsage","currentUsage","segmentCommand","subcommandInterpreter","segmentPositional","name","subcommand","description","hint","commandChained","value","positionals","options","positional","operation","inputs","handler","optionsUsage","optionKey","optionInput","positionalsUsage","positionalInput","readerArgs","optionsDecoders","positionalsDecoders","optionsValues","positionalsValues","positionalDecoder","context","typeBoolean","input","lower","TypoError","TypoText","TypoString","typoStyleQuote","typeDate","timestampMs","typeNumber","parsed","typeInteger","typeUrl","typeString","typeMapped","before","after","typoStyleLogic","typeOneOf","content","values","value","valuesPreview","typeTuple","elementTypes","separator","elementType","splits","split","index","typeList","optionFlag","definition","label","typeBoolean","readerOptions","key","registerOption","optionValues","TypoError","TypoText","TypoString","typoStyleConstants","optionValue","error","decodeValue","optionSingleValue","optionRepeatable","params","text","typoStyleUserInput","typoStyleLogic","long","short","aliases","valued","longs","shorts","positionalRequired","definition","label","readerPositionals","positional","TypoError","TypoText","TypoString","typoStyleUserInput","decodeValue","positionalOptional","error","positionalVariadics","positionals","type","input","typoStyleLogic","_args","_parsedIndex","_parsedDouble","_keyByLong","_keyByShort","_valuedByKey","_resultByKey","_ReaderArgs_instances","consumeArg_fn","processedAsPositional_fn","consumeOptionLong_fn","tryConsumeOptionShort_fn","consumeOptionValue_fn","acknowledgeOption_fn","isValidOptionName_fn","ReaderArgs","args","__privateAdd","__privateSet","definition","key","long","short","__privateMethod","__privateGet","i","shortSlice","shortOther","optionResult","arg","__privateWrapper","valueIndexStart","shortIndexStart","shortIndexEnd","result","TypoError","TypoText","TypoString","typoStyleConstants","direct","constant","rest","typoStyleQuote","value","name","usageToStyledLines","params","cliName","commandUsage","typoSupport","lines","segments","textUsageHero","textConstants","segment","textUserInput","introText","TypoText","textUsageText","textDelimiter","textSubtleInfo","detail","detailText","textBlockTitle","typoGrid","TypoGrid","positionalUsage","typoGridRow","createInformationals","row","subcommandUsage","optionUsage","example","exampleExplanationText","commandLineText","commandArg","option","usage","informationals","textUsefulInfo","value","TypoString","typoStyleLogic","typoStyleRegularStrong","typoStyleTitle","typoStyleRegularWeaker","typoStyleConstants","typoStyleUserInput","runAndExit","cliName","cliArgs","context","command","options","readerArgs","ReaderArgs","usageOnHelp","buildVersion","commandDecoder","onExit","typoSupport","TypoSupport","computeUsageString","commandInterpreter","executionError","handleError","parsingError","onError","error","usageToStyledLines"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/Typo.ts","../src/lib/Command.ts","../src/lib/Operation.ts","../src/lib/Type.ts","../src/lib/Option.ts","../src/lib/Positional.ts","../src/lib/Reader.ts","../src/lib/Usage.ts","../src/lib/Run.ts"],"sourcesContent":["export * from \"./lib/Command\";\nexport * from \"./lib/Operation\";\nexport * from \"./lib/Option\";\nexport * from \"./lib/Positional\";\nexport * from \"./lib/Reader\";\nexport * from \"./lib/Run\";\nexport * from \"./lib/Type\";\nexport * from \"./lib/Typo\";\nexport * from \"./lib/Usage\";\n","/**\n * Color names for terminal styling, used by {@link TypoStyle}.\n * `dark*` = standard ANSI (30–37); `bright*` = high-intensity (90–97).\n */\nexport type TypoColor =\n | \"darkBlack\"\n | \"darkRed\"\n | \"darkGreen\"\n | \"darkYellow\"\n | \"darkBlue\"\n | \"darkMagenta\"\n | \"darkCyan\"\n | \"darkWhite\"\n | \"brightBlack\"\n | \"brightRed\"\n | \"brightGreen\"\n | \"brightYellow\"\n | \"brightBlue\"\n | \"brightMagenta\"\n | \"brightCyan\"\n | \"brightWhite\";\n\n/**\n * Visual styling applied by a {@link TypoSupport} instance.\n * All fields are optional; ignored entirely in `\"none\"` mode.\n */\nexport type TypoStyle = {\n /**\n * Letter case.\n */\n case?: \"upper\" | \"lower\";\n /**\n * Foreground (text) color.\n */\n fgColor?: TypoColor;\n /**\n * Background color.\n */\n bgColor?: TypoColor;\n /**\n * Reduced intensity.\n */\n dim?: boolean;\n /**\n * Bold.\n */\n bold?: boolean;\n /**\n * Italic.\n */\n italic?: boolean;\n /**\n * Underline.\n */\n underline?: boolean;\n /**\n * Strikethrough.\n */\n strikethrough?: boolean;\n};\n\n/**\n * Section title style. Bold dark-green.\n */\nexport const typoStyleTitle: TypoStyle = {\n fgColor: \"darkGreen\",\n bold: true,\n};\n/**\n * Logic/type identifier style. Bold dark-magenta.\n */\nexport const typoStyleLogic: TypoStyle = {\n fgColor: \"darkMagenta\",\n bold: true,\n};\n/**\n * Quoted user-input style. Bold dark-yellow.\n */\nexport const typoStyleQuote: TypoStyle = {\n fgColor: \"darkYellow\",\n bold: true,\n};\n\n/**\n * Error label style. Bold dark-red.\n */\nexport const typoStyleFailure: TypoStyle = {\n fgColor: \"darkRed\",\n bold: true,\n};\n\n/**\n * Option/command name style. Bold dark-cyan.\n */\nexport const typoStyleConstants: TypoStyle = {\n fgColor: \"darkCyan\",\n bold: true,\n};\n/**\n * Positional/user-input label style. Bold dark-blue.\n */\nexport const typoStyleUserInput: TypoStyle = {\n fgColor: \"darkBlue\",\n bold: true,\n};\n\n/**\n * Strong text style. Bold.\n */\nexport const typoStyleRegularStrong: TypoStyle = {\n bold: true,\n};\n/**\n * Subtle text style. Italic and dim.\n */\nexport const typoStyleRegularWeaker: TypoStyle = {\n italic: true,\n dim: true,\n};\n\n/**\n * Immutable styled string segment. Compose into a {@link TypoText}.\n */\nexport class TypoString {\n #value: string;\n #typoStyle: TypoStyle;\n /**\n * @param value - Raw text content.\n * @param typoStyle - Style to apply when rendering. Defaults to `{}` (no style).\n */\n constructor(value: string, typoStyle: TypoStyle = {}) {\n this.#value = value;\n this.#typoStyle = typoStyle;\n }\n /**\n * Returns the text styled by `typoSupport`.\n *\n * @param typoSupport - Rendering mode.\n */\n computeStyledString(typoSupport: TypoSupport): string {\n return typoSupport.computeStyledString(this.#value, this.#typoStyle);\n }\n /**\n * Returns the raw text.\n */\n getRawString(): string {\n return this.#value;\n }\n}\n\n/**\n * Mutable sequence of {@link TypoString} segments.\n */\nexport class TypoText {\n #typoStrings: Array<TypoString>;\n /**\n * @param segments - Initial text segments\n */\n constructor(\n ...segments: Array<TypoText | Array<TypoString> | TypoString | string>\n ) {\n this.#typoStrings = [];\n for (const typoPart of segments) {\n this.push(typoPart);\n }\n }\n /**\n * Appends new text segment(s).\n *\n * @param segment - Text segment(s) to append.\n */\n push(segment: TypoText | Array<TypoString> | TypoString | string) {\n if (typeof segment === \"string\") {\n this.#typoStrings.push(new TypoString(segment));\n } else if (segment instanceof TypoText) {\n this.#typoStrings.push(...segment.#typoStrings);\n } else if (Array.isArray(segment)) {\n for (const typoString of segment) {\n this.#typoStrings.push(typoString);\n }\n } else {\n this.#typoStrings.push(segment);\n }\n }\n /**\n * Renders all segments into a single styled string.\n *\n * @param typoSupport - Rendering mode.\n * @returns Concatenated styled string.\n */\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoStrings\n .map((t) => t.computeStyledString(typoSupport))\n .join(\"\");\n }\n /**\n * Returns the concatenated raw text.\n */\n computeRawString(): string {\n return this.#typoStrings.map((t) => t.getRawString()).join(\"\");\n }\n /**\n * Returns the total raw character count.\n */\n computeRawLength(): number {\n let length = 0;\n for (const typoString of this.#typoStrings) {\n length += typoString.getRawString().length;\n }\n return length;\n }\n}\n\n/**\n * Column-aligned grid of {@link TypoText} cells.\n * Each column is padded to the widest cell (raw chars); the last column is not padded.\n */\nexport class TypoGrid {\n #typoRows: Array<Array<TypoText>>;\n constructor() {\n this.#typoRows = [];\n }\n /**\n * Appends a row. All rows should have the same cell count.\n *\n * @param cells - Ordered {@link TypoText} cells.\n */\n pushRow(cells: Array<TypoText>) {\n this.#typoRows.push(cells);\n }\n /**\n * Renders as an array of styled, column-padded strings.\n *\n * @param typoSupport - Rendering mode.\n * @returns Array of styled strings.\n */\n computeStyledLines(typoSupport: TypoSupport): Array<string> {\n const widths = new Array<number>();\n const styledLines = new Array<string>();\n for (const typoGridRow of this.#typoRows) {\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n const width = typoGridCell.computeRawLength();\n if (\n widths[typoGridColumnIndex] === undefined ||\n width > widths[typoGridColumnIndex]!\n ) {\n widths[typoGridColumnIndex] = width;\n }\n }\n }\n for (const typoGridRow of this.#typoRows) {\n const styledGridRow = new Array<string>();\n for (\n let typoGridColumnIndex = 0;\n typoGridColumnIndex < typoGridRow.length;\n typoGridColumnIndex++\n ) {\n const typoGridCell = typoGridRow[typoGridColumnIndex]!;\n styledGridRow.push(typoGridCell.computeStyledString(typoSupport));\n if (typoGridColumnIndex < typoGridRow.length - 1) {\n const width = typoGridCell.computeRawLength();\n const padding = \" \".repeat(widths[typoGridColumnIndex]! - width);\n styledGridRow.push(padding);\n }\n }\n styledLines.push(styledGridRow.join(\"\"));\n }\n return styledLines;\n }\n}\n\n/**\n * `Error` subclass with a {@link TypoText} styled message for rich terminal output.\n * Chains `TypoError` sources after `\": \"`.\n */\nexport class TypoError extends Error {\n #typoText: TypoText;\n /**\n * @param currentTypoText - Styled message for this error.\n * @param source - Optional cause; `TypoError` chains styled text, `Error` appends `.message`, else `String()`.\n */\n constructor(currentTypoText: TypoText, source?: unknown) {\n const typoText = new TypoText();\n typoText.push(currentTypoText);\n if (source instanceof TypoError) {\n typoText.push(new TypoString(\": \"));\n typoText.push(source.#typoText);\n } else if (source instanceof Error) {\n typoText.push(new TypoString(`: ${source.message}`));\n } else if (source !== undefined) {\n typoText.push(new TypoString(`: ${String(source)}`));\n }\n super(typoText.computeRawString());\n this.#typoText = typoText;\n }\n /**\n * Renders the styled message (without `\"Error:\"` prefix).\n *\n * @param typoSupport - Rendering mode.\n * @returns Styled error string.\n */\n computeStyledString(typoSupport: TypoSupport): string {\n return this.#typoText.computeStyledString(typoSupport);\n }\n /**\n * Runs `thrower`; wraps any thrown error as a `TypoError` with `context()` prepended.\n *\n * @typeParam Value - Return type of `thrower`.\n * @param thrower - Function to execute; result passed through on success.\n * @param context - Produces the {@link TypoText} prepended to the caught error.\n * @returns Value from `thrower`.\n * @throws `TypoError` wrapping the original error with context prepended.\n */\n static tryWithContext<Value>(\n thrower: () => Value,\n context: () => TypoText,\n ): Value {\n try {\n return thrower();\n } catch (error) {\n throw new TypoError(context(), error);\n }\n }\n}\n\n/**\n * Controls ANSI terminal styling. Create via the static factory methods.\n */\nexport class TypoSupport {\n #kind: \"none\" | \"tty\" | \"mock\";\n private constructor(kind: \"none\" | \"tty\" | \"mock\") {\n this.#kind = kind;\n }\n /**\n * Plain text — no ANSI codes.\n */\n static none(): TypoSupport {\n return new TypoSupport(\"none\");\n }\n /**\n * ANSI escape codes for color terminals.\n */\n static tty(): TypoSupport {\n return new TypoSupport(\"tty\");\n }\n /**\n * Deterministic textual styling for snapshot tests.\n */\n static mock(): TypoSupport {\n return new TypoSupport(\"mock\");\n }\n /**\n * Auto-detects styling mode from the process environment on best-effort basis.\n */\n static inferFromEnv(): TypoSupport {\n if (!process || !process.env) {\n return TypoSupport.none();\n }\n function readEnvVar(name: string) {\n if (!(name in process.env)) {\n return undefined;\n }\n return process.env[name];\n }\n const envForceColor = readEnvVar(\"FORCE_COLOR\");\n if (envForceColor === \"0\") {\n return TypoSupport.none();\n }\n if (envForceColor !== undefined) {\n TypoSupport.tty();\n }\n if (readEnvVar(\"NO_COLOR\") !== undefined) {\n return TypoSupport.none();\n }\n if (readEnvVar(\"MOCK_COLOR\") !== undefined) {\n return TypoSupport.mock();\n }\n return TypoSupport.tty();\n }\n /**\n * Applies `typoStyle` to `value` according to the current mode.\n *\n * @param value - Raw text.\n * @param typoStyle - Style to apply.\n * @returns Styled string.\n */\n computeStyledString(value: string, typoStyle: TypoStyle): string {\n let styledValue = value;\n if (typoStyle.case === \"upper\") {\n styledValue = styledValue.toUpperCase();\n }\n if (typoStyle.case === \"lower\") {\n styledValue = styledValue.toLowerCase();\n }\n if (this.#kind === \"none\") {\n return styledValue;\n }\n if (this.#kind === \"tty\") {\n const fgColorCode = typoStyle.fgColor\n ? ttyCodeFgColors[typoStyle.fgColor]\n : \"\";\n const bgColorCode = typoStyle.bgColor\n ? ttyCodeBgColors[typoStyle.bgColor]\n : \"\";\n const boldCode = typoStyle.bold ? ttyCodeBold : \"\";\n const dimCode = typoStyle.dim ? ttyCodeDim : \"\";\n const italicCode = typoStyle.italic ? ttyCodeItalic : \"\";\n const underlineCode = typoStyle.underline ? ttyCodeUnderline : \"\";\n const strikethroughCode = typoStyle.strikethrough\n ? ttyCodeStrikethrough\n : \"\";\n return `${fgColorCode}${bgColorCode}${boldCode}${dimCode}${italicCode}${underlineCode}${strikethroughCode}${styledValue}${ttyCodeReset}`;\n }\n if (this.#kind === \"mock\") {\n const fgColorPart = typoStyle.fgColor\n ? `{${styledValue}}@${typoStyle.fgColor}`\n : styledValue;\n const bgColorPart = typoStyle.bgColor\n ? `{${fgColorPart}}#${typoStyle.bgColor}`\n : fgColorPart;\n const boldPart = typoStyle.bold ? `{${bgColorPart}}+` : bgColorPart;\n const dimPart = typoStyle.dim ? `{${boldPart}}-` : boldPart;\n const italicPart = typoStyle.italic ? `{${dimPart}}*` : dimPart;\n const underlinePart = typoStyle.underline\n ? `{${italicPart}}_`\n : italicPart;\n const strikethroughPart = typoStyle.strikethrough\n ? `{${underlinePart}}~`\n : underlinePart;\n return strikethroughPart;\n }\n throw new Error(`Unknown TypoSupport kind: ${this.#kind}`);\n }\n /**\n * Formats any thrown value as `\"Error: <message>\"` with {@link typoStyleFailure} on the prefix.\n *\n * @param error - Any thrown value.\n * @returns Styled error string.\n */\n computeStyledErrorMessage(error: unknown): string {\n return [\n this.computeStyledString(\"Error:\", typoStyleFailure),\n error instanceof TypoError\n ? error.computeStyledString(this)\n : error instanceof Error\n ? error.message\n : String(error),\n ].join(\" \");\n }\n}\n\nconst ttyCodeReset = \"\\x1b[0m\";\nconst ttyCodeBold = \"\\x1b[1m\";\nconst ttyCodeDim = \"\\x1b[2m\";\nconst ttyCodeItalic = \"\\x1b[3m\";\nconst ttyCodeUnderline = \"\\x1b[4m\";\nconst ttyCodeStrikethrough = \"\\x1b[9m\";\nconst ttyCodeFgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[30m\",\n darkRed: \"\\x1b[31m\",\n darkGreen: \"\\x1b[32m\",\n darkYellow: \"\\x1b[33m\",\n darkBlue: \"\\x1b[34m\",\n darkMagenta: \"\\x1b[35m\",\n darkCyan: \"\\x1b[36m\",\n darkWhite: \"\\x1b[37m\",\n brightBlack: \"\\x1b[90m\",\n brightRed: \"\\x1b[91m\",\n brightGreen: \"\\x1b[92m\",\n brightYellow: \"\\x1b[93m\",\n brightBlue: \"\\x1b[94m\",\n brightMagenta: \"\\x1b[95m\",\n brightCyan: \"\\x1b[96m\",\n brightWhite: \"\\x1b[97m\",\n};\nconst ttyCodeBgColors: Record<TypoColor, string> = {\n darkBlack: \"\\x1b[40m\",\n darkRed: \"\\x1b[41m\",\n darkGreen: \"\\x1b[42m\",\n darkYellow: \"\\x1b[43m\",\n darkBlue: \"\\x1b[44m\",\n darkMagenta: \"\\x1b[45m\",\n darkCyan: \"\\x1b[46m\",\n darkWhite: \"\\x1b[47m\",\n brightBlack: \"\\x1b[100m\",\n brightRed: \"\\x1b[101m\",\n brightGreen: \"\\x1b[102m\",\n brightYellow: \"\\x1b[103m\",\n brightBlue: \"\\x1b[104m\",\n brightMagenta: \"\\x1b[105m\",\n brightCyan: \"\\x1b[106m\",\n brightWhite: \"\\x1b[107m\",\n};\n","import { Operation } from \"./Operation\";\nimport { ReaderArgs } from \"./Reader\";\nimport {\n TypoError,\n TypoString,\n typoStyleQuote,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\nimport { UsageCommand } from \"./Usage\";\n\n/**\n * A CLI command. Created with {@link command}, {@link commandWithSubcommands}, or {@link commandChained}.\n *\n * @typeParam Context - Injected at execution; forwarded to handlers.\n * @typeParam Result - Produced on execution; typically `void`.\n */\nexport type Command<Context, Result> = {\n /**\n * Returns static metadata.\n */\n getInformation(): CommandInformation;\n /**\n * Registers options/positionals on `readerArgs`; returns a {@link CommandDecoder}.\n */\n consumeAndMakeDecoder(\n readerArgs: ReaderArgs,\n ): CommandDecoder<Context, Result>;\n};\n\n/**\n * Produced by {@link Command.consumeAndMakeDecoder}.\n *\n * @typeParam Context - See {@link Command}.\n * @typeParam Result - See {@link Command}.\n */\nexport type CommandDecoder<Context, Result> = {\n /**\n * Returns {@link UsageCommand} for the current command path.\n */\n generateUsage(): UsageCommand;\n /**\n * Creates a ready-to-execute {@link CommandInterpreter}.\n *\n * @throws {@link TypoError} if parsing or decoding failed.\n */\n decodeAndMakeInterpreter(): CommandInterpreter<Context, Result>;\n};\n\n/**\n * A fully parsed, decoded and ready-to-execute command.\n *\n * @typeParam Context - Context passed to the handler.\n * @typeParam Result - Value produced on success.\n */\nexport type CommandInterpreter<Context, Result> = {\n /**\n * Executes with the provided context.\n */\n executeWithContext(context: Context): Promise<Result>;\n};\n\n/**\n * Command metadata shown in `--help` output.\n */\nexport type CommandInformation = {\n /**\n * Shown in the usage header.\n */\n description: string;\n /**\n * Shown in parentheses, e.g. `\"deprecated\"`, `\"experimental\"`.\n */\n hint?: string;\n /**\n * Extra lines printed below the description.\n */\n details?: Array<string>;\n /**\n * Shown in the `Examples:` section.\n */\n examples?: Array<{\n /**\n * Explanation shown above the example.\n */\n explanation: string;\n /**\n * Example command args.\n */\n commandArgs: Array<\n | string\n | { positional: string }\n | { subcommand: string }\n | {\n option:\n | { long: string; inlined?: string; separated?: Array<string> }\n | { short: string; inlined?: string; separated?: Array<string> };\n }\n >;\n }>;\n};\n\n/**\n * Creates a leaf command that directly executes an {@link Operation}.\n *\n * @typeParam Context - Context forwarded to the handler.\n * @typeParam Result - Value returned by the handler.\n *\n * @param information - Command metadata.\n * @param operation - Options, positionals, and handler.\n * @returns A {@link Command}.\n *\n * @example\n * ```ts\n * const greet = command(\n * { description: \"Greet a user\" },\n * operation(\n * { options: {}, positionals: [positionalRequired({ type: type(\"name\") })] },\n * async (_ctx, { positionals: [name] }) => console.log(`Hello, ${name}!`),\n * ),\n * );\n * ```\n */\nexport function command<Context, Result>(\n information: CommandInformation,\n operation: Operation<Context, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n try {\n const operationDecoder = operation.consumeAndMakeDecoder(readerArgs);\n const endPositional = readerArgs.consumePositional();\n if (endPositional !== undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Unexpected argument: `),\n new TypoString(`\"${endPositional}\"`, typoStyleQuote),\n ),\n );\n }\n return {\n generateUsage: () => generateUsageLeaf(information, operation),\n decodeAndMakeInterpreter() {\n const operationInterpreter =\n operationDecoder.decodeAndMakeInterpreter();\n return {\n async executeWithContext(context: Context) {\n return await operationInterpreter.executeWithContext(context);\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage: () => generateUsageLeaf(information, operation),\n decodeAndMakeInterpreter() {\n throw error;\n },\n };\n }\n },\n };\n}\n\n/**\n * Creates a command that runs `operation` first, then dispatches to a named subcommand.\n *\n * @typeParam Context - Context accepted by `operation`.\n * @typeParam Payload - Output of `operation`; becomes the subcommand's context.\n * @typeParam Result - Value produced by the selected subcommand.\n *\n * @param information - Command metadata.\n * @param operation - Runs first; output becomes the subcommand's context.\n * @param subcommands - Map of subcommand names to their {@link Command}s.\n * @returns A dispatching {@link Command}.\n *\n * @example\n * ```ts\n * const rootCmd = commandWithSubcommands(\n * { description: \"My CLI\" },\n * operation({ options: {}, positionals: [] }, async (ctx) => ctx),\n * {\n * deploy: command({ description: \"Deploy\" }, deployOperation),\n * rollback: command({ description: \"Rollback\" }, rollbackOperation),\n * },\n * );\n * ```\n */\nexport function commandWithSubcommands<Context, Payload, Result>(\n information: CommandInformation,\n operation: Operation<Context, Payload>,\n subcommands: { [subcommand: string]: Command<Payload, Result> },\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n try {\n const operationDecoder = operation.consumeAndMakeDecoder(readerArgs);\n const subcommandName = readerArgs.consumePositional();\n if (subcommandName === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<subcommand>`, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n const subcommandInput = subcommands[subcommandName];\n if (subcommandInput === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(`<subcommand>`, typoStyleUserInput),\n new TypoString(`: Invalid value: `),\n new TypoString(`\"${subcommandName}\"`, typoStyleQuote),\n ),\n );\n }\n const subcommandDecoder =\n subcommandInput.consumeAndMakeDecoder(readerArgs);\n return {\n generateUsage() {\n const subcommandUsage = subcommandDecoder.generateUsage();\n const currentUsage = generateUsageLeaf(information, operation);\n currentUsage.segments.push({ subcommand: subcommandName });\n currentUsage.segments.push(...subcommandUsage.segments);\n currentUsage.information = subcommandUsage.information;\n currentUsage.positionals.push(...subcommandUsage.positionals);\n currentUsage.subcommands = subcommandUsage.subcommands;\n currentUsage.options.push(...subcommandUsage.options);\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n const operationInterpreter =\n operationDecoder.decodeAndMakeInterpreter();\n const subcommandInterpreter =\n subcommandDecoder.decodeAndMakeInterpreter();\n return {\n async executeWithContext(context: Context) {\n return await subcommandInterpreter.executeWithContext(\n await operationInterpreter.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const currentUsage = generateUsageLeaf(information, operation);\n currentUsage.segments.push({ positional: \"<subcommand>\" });\n for (const [name, subcommand] of Object.entries(subcommands)) {\n const { description, hint } = subcommand.getInformation();\n currentUsage.subcommands.push({ name, description, hint });\n }\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n throw error;\n },\n };\n }\n },\n };\n}\n\n/**\n * Chains an {@link Operation} and a {@link Command}: `operation` runs first, its\n * output becomes `subcommand`'s context. No token is consumed for routing.\n *\n * @typeParam Context - Context accepted by `operation`.\n * @typeParam Payload - Output of `operation`; becomes `subcommand`'s context.\n * @typeParam Result - Value produced by `subcommand`.\n *\n * @param information - Command metadata.\n * @param operation - Runs first; output becomes `subcommand`'s context.\n * @param subcommand - Runs after `operation`.\n * @returns A {@link Command} composing both stages.\n */\nexport function commandChained<Context, Payload, Result>(\n information: CommandInformation,\n operation: Operation<Context, Payload>,\n subcommand: Command<Payload, Result>,\n): Command<Context, Result> {\n return {\n getInformation() {\n return information;\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n try {\n const operationDecoder = operation.consumeAndMakeDecoder(readerArgs);\n const subcommandDecoder = subcommand.consumeAndMakeDecoder(readerArgs);\n return {\n generateUsage() {\n const subcommandUsage = subcommandDecoder.generateUsage();\n const currentUsage = generateUsageLeaf(information, operation);\n currentUsage.segments.push(...subcommandUsage.segments);\n currentUsage.information = subcommandUsage.information;\n currentUsage.positionals.push(...subcommandUsage.positionals);\n currentUsage.subcommands = subcommandUsage.subcommands;\n currentUsage.options.push(...subcommandUsage.options);\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n const operationInterpreter =\n operationDecoder.decodeAndMakeInterpreter();\n const subcommandInterpreter =\n subcommandDecoder.decodeAndMakeInterpreter();\n return {\n async executeWithContext(context: Context) {\n return await subcommandInterpreter.executeWithContext(\n await operationInterpreter.executeWithContext(context),\n );\n },\n };\n },\n };\n } catch (error) {\n return {\n generateUsage() {\n const currentUsage = generateUsageLeaf(information, operation);\n currentUsage.segments.push({ positional: \"[REST]...\" });\n return currentUsage;\n },\n decodeAndMakeInterpreter() {\n throw error;\n },\n };\n }\n },\n };\n}\n\nfunction generateUsageLeaf(\n information: CommandInformation,\n operation: Operation<any, any>,\n): UsageCommand {\n const { positionals, options } = operation.generateUsage();\n return {\n segments: positionals.map((positional) => ({\n positional: positional.label,\n })),\n information,\n positionals,\n subcommands: [],\n options,\n };\n}\n","import { Option, OptionDecoder } from \"./Option\";\nimport { Positional, PositionalDecoder } from \"./Positional\";\nimport { ReaderArgs } from \"./Reader\";\nimport { UsageOption, UsagePositional } from \"./Usage\";\n\n/**\n * Options, positionals, and an async handler that together form the logic of a CLI command.\n *\n * Created with {@link operation} and passed to {@link command},\n * {@link commandWithSubcommands}, or {@link commandChained}.\n *\n * @typeParam Context - Injected at execution; forwarded to handlers.\n * @typeParam Result - Value produced on execution; typically `void`.\n */\nexport type Operation<Context, Result> = {\n /**\n * Returns usage metadata without consuming any arguments.\n */\n generateUsage(): {\n /**\n * Registered options.\n */\n options: Array<UsageOption>;\n /**\n * Declared positionals, in order.\n */\n positionals: Array<UsagePositional>;\n };\n /**\n * Consumes args from `readerArgs` and returns an {@link OperationDecoder}.\n */\n consumeAndMakeDecoder(\n readerArgs: ReaderArgs,\n ): OperationDecoder<Context, Result>;\n};\n\n/**\n * Produced by {@link Operation.consumeAndMakeDecoder}.\n *\n * @typeParam Context - See {@link Operation}.\n * @typeParam Result - See {@link Operation}.\n */\nexport type OperationDecoder<Context, Result> = {\n /**\n * Creates a ready-to-execute {@link OperationInterpreter}.\n *\n * @throws {@link TypoError} if parsing or decoding failed.\n */\n decodeAndMakeInterpreter(): OperationInterpreter<Context, Result>;\n};\n\n/**\n * A fully parsed, decoded and ready-to-execute operation.\n *\n * @typeParam Context - Caller-supplied context.\n * @typeParam Result - Value produced on success.\n */\nexport type OperationInterpreter<Context, Result> = {\n /**\n * Executes with the provided context.\n */\n executeWithContext(context: Context): Promise<Result>;\n};\n\n/**\n * Creates an {@link Operation} from options, positionals, and an async handler.\n *\n * The `handler` receives `context` and `inputs` with decoded `options` and `positionals`.\n *\n * @typeParam Context - Context type accepted by the handler.\n * @typeParam Result - Return type of the handler.\n * @typeParam Options - Map of option keys to parsed value types.\n * @typeParam Positionals - Tuple of parsed positional value types, in order.\n *\n * @param inputs - Options and positionals this operation accepts.\n * @param inputs.options - Map of keys to {@link Option} descriptors.\n * @param inputs.positionals - Ordered array of {@link Positional} descriptors.\n * @param handler - Async function implementing the command logic.\n * @returns An {@link Operation}.\n *\n * @example\n * ```ts\n * const greetOperation = operation(\n * {\n * options: {\n * loud: optionFlag({ long: \"loud\", description: \"Print in uppercase\", default: false }),\n * },\n * positionals: [\n * positionalRequired({ type: type(\"name\"), description: \"Name to greet\" }),\n * ],\n * },\n * async function (_ctx, { options: { loud }, positionals: [name] }) {\n * const message = `Hello, ${name}!`;\n * console.log(loud ? message.toUpperCase() : message);\n * },\n * );\n * ```\n */\nexport function operation<\n Context,\n Result,\n Options extends { [option: string]: any },\n const Positionals extends Array<any>,\n>(\n inputs: {\n options: { [K in keyof Options]: Option<Options[K]> };\n positionals: { [K in keyof Positionals]: Positional<Positionals[K]> };\n },\n handler: (\n context: Context,\n inputs: {\n options: Options;\n positionals: Positionals;\n },\n ) => Promise<Result>,\n): Operation<Context, Result> {\n return {\n generateUsage() {\n const optionsUsage = new Array<UsageOption>();\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n optionsUsage.push(optionInput.generateUsage());\n }\n const positionalsUsage = new Array<UsagePositional>();\n for (const positionalInput of inputs.positionals) {\n positionalsUsage.push(positionalInput.generateUsage());\n }\n return { options: optionsUsage, positionals: positionalsUsage };\n },\n consumeAndMakeDecoder(readerArgs: ReaderArgs) {\n const optionsDecoders: Record<string, OptionDecoder<any>> = {};\n for (const optionKey in inputs.options) {\n const optionInput = inputs.options[optionKey]!;\n optionsDecoders[optionKey] =\n optionInput.registerAndMakeDecoder(readerArgs);\n }\n const positionalsDecoders: Array<PositionalDecoder<any>> = [];\n for (const positionalInput of inputs.positionals) {\n positionalsDecoders.push(\n positionalInput.consumeAndMakeDecoder(readerArgs),\n );\n }\n return {\n decodeAndMakeInterpreter() {\n const optionsValues: any = {};\n for (const optionKey in optionsDecoders) {\n optionsValues[optionKey] =\n optionsDecoders[optionKey]!.getAndDecodeValue();\n }\n const positionalsValues: any = [];\n for (const positionalDecoder of positionalsDecoders) {\n positionalsValues.push(positionalDecoder.decodeValue());\n }\n return {\n executeWithContext(context: Context) {\n return handler(context, {\n options: optionsValues,\n positionals: positionalsValues,\n });\n },\n };\n },\n };\n },\n };\n}\n","import { statSync } from \"fs\";\nimport {\n TypoError,\n TypoString,\n typoStyleLogic,\n typoStyleQuote,\n TypoText,\n} from \"./Typo\";\n\n/**\n * Decodes a raw CLI string into a typed value.\n * A pair of a human-readable `content` name and a `decoder` function.\n *\n * Built-in: {@link type}, {@link typeBoolean}, {@link typeNumber},\n * {@link typeInteger}, {@link typeDatetime}, {@link typeUrl}.\n * Composite: {@link typeChoice}, {@link typeConverted}, {@link typeTuple}, {@link typeList}.\n *\n * @typeParam Value - Type produced by the decoder.\n */\nexport type Type<Value> = {\n /**\n * Human-readable name shown in help and errors (e.g. `\"name\"`, `\"number\"`).\n */\n content: string;\n /**\n * Decodes a raw CLI string into `Value`.\n *\n * @param input - Raw string from the command line.\n * @returns The decoded value.\n * @throws {@link TypoError} on invalid input.\n */\n decoder(input: string): Value;\n};\n\n/**\n * Decodes a string to `boolean` (case-insensitive).\n * Used by {@link optionFlag} for `--flag=<value>`.\n *\n * @example\n * ```ts\n * typeBoolean(\"flag\").decoder(\"true\") // → true\n * typeBoolean(\"flag\").decoder(\"yes\") // → true\n * typeBoolean(\"flag\").decoder(\"y\") // → true\n * typeBoolean(\"flag\").decoder(\"false\") // → false\n * typeBoolean(\"flag\").decoder(\"no\") // → false\n * typeBoolean(\"flag\").decoder(\"n\") // → false\n * ```\n */\nexport function typeBoolean(name?: string): Type<boolean> {\n return {\n content: name ?? \"boolean\",\n decoder(input: string) {\n const lower = input.toLowerCase();\n if (booleanValuesTrue.has(lower)) {\n return true;\n }\n if (booleanValuesFalse.has(lower)) {\n return false;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Not a boolean: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n },\n };\n}\nconst booleanValuesTrue = new Set([\"true\", \"yes\", \"on\", \"1\", \"y\", \"t\"]);\nconst booleanValuesFalse = new Set([\"false\", \"no\", \"off\", \"0\", \"n\", \"f\"]);\n\n/**\n * Parses a date/time string via `Date.parse`.\n * Accepts any format supported by `Date.parse`, including ISO 8601.\n *\n * @example\n * ```ts\n * typeDatetime(\"my-datetime\").decoder(\"2024-01-15\") // → Date object for 2024-01-15\n * typeDatetime(\"my-datetime\").decoder(\"2024-01-15T13:45:30Z\") // → Date object for 2024-01-15 13:45:30 UTC\n * typeDatetime(\"my-datetime\").decoder(\"not a date\") // throws TypoError\n * ```\n */\nexport function typeDatetime(name?: string): Type<Date> {\n return {\n content: name ?? \"datetime\",\n decoder(input: string) {\n try {\n const timestampMs = Date.parse(input);\n if (isNaN(timestampMs)) {\n throw new Error();\n }\n return new Date(timestampMs);\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Not a valid ISO_8601 datetime: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n };\n}\n\n/**\n * Parses a string to `number` via `Number()`; `NaN` throws {@link TypoError}.\n *\n * @example\n * ```ts\n * typeNumber(\"my-number\").decoder(\"3.14\") // → 3.14\n * typeNumber(\"my-number\").decoder(\"-1\") // → -1\n * typeNumber(\"my-number\").decoder(\"hello\") // throws TypoError\n * ```\n */\nexport function typeNumber(name?: string): Type<number> {\n return {\n content: name ?? \"number\",\n decoder(input: string) {\n try {\n const parsed = Number(input);\n if (isNaN(parsed)) {\n throw new Error();\n }\n return parsed;\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Not a number: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n };\n}\n\n/**\n * Parses an integer string to `bigint` via `BigInt()`.\n * Floats and non-numeric strings throw {@link TypoError}.\n *\n * @example\n * ```ts\n * typeInteger(\"my-integer\").decoder(\"42\") // → 42n\n * typeInteger(\"my-integer\").decoder(\"3.14\") // throws TypoError\n * typeInteger(\"my-integer\").decoder(\"abc\") // throws TypoError\n * ```\n */\nexport function typeInteger(name?: string): Type<bigint> {\n return {\n content: name ?? \"integer\",\n decoder(input: string) {\n try {\n return BigInt(input);\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Not an integer: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n };\n}\n\n/**\n * Parses an absolute URL string to a `URL` object.\n * Relative or malformed URLs throw {@link TypoError}.\n *\n * @example\n * ```ts\n * typeUrl(\"my-url\").decoder(\"https://example.com\") // → URL { href: \"https://example.com/\", ... }\n * typeUrl(\"my-url\").decoder(\"not-a-url\") // throws TypoError\n * ```\n */\nexport function typeUrl(name?: string): Type<URL> {\n return {\n content: name ?? \"url\",\n decoder(input: string) {\n try {\n return new URL(input);\n } catch {\n throw new TypoError(\n new TypoText(\n new TypoString(`Not an URL: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n },\n };\n}\n\n/**\n * A named type that accepts any string as input.\n * @param name - Name shown in help and errors (e.g. `\"my-value\"`).\n * @example\n * ```ts\n * type(\"greeting\").decoder(\"hello\") // → \"hello\"\n * type(\"greeting\").decoder(\"\") // → \"\"\n * ```\n */\nexport function type(name?: string): Type<string> {\n return {\n content: name ?? \"string\",\n decoder: (input: string) => input,\n };\n}\n\n/**\n * Chains `before`'s decoder with an `after` transformation.\n * `before` errors are prefixed with `\"from: <content>\"` for traceability.\n *\n * @typeParam Before - Intermediate type from `before.decoder`.\n * @typeParam After - Final type from `after.decoder`.\n *\n * @param name - Name shown in help and errors (e.g. `\"my-value\"`).\n * @param before - Base type to decode the raw string.\n * @param mapper - Transforms `before`'s output to the final value; errors are wrapped with context.\n * @returns A {@link Type}`<After>`.\n *\n * @example\n * ```ts\n * const typePort = typeConverted(\"port\", typeNumber(), (n) => {\n * if (n < 1 || n > 65535) throw new Error(\"Out of range\");\n * return n;\n * });\n * // \"--port 8080\" → 8080\n * // \"--port 99999\" → TypoError: --port: <PORT>: Port: Out of range\n * ```\n */\nexport function typeConverted<Before, After>(\n name: string,\n before: Type<Before>,\n mapper: (value: Before) => After,\n): Type<After> {\n return {\n content: name,\n decoder: (input: string) => {\n return mapper(\n TypoError.tryWithContext(\n () => before.decoder(input),\n () =>\n new TypoText(\n new TypoString(\"from: \"),\n new TypoString(before.content, typoStyleLogic),\n ),\n ),\n );\n },\n };\n}\n\n/**\n * Adds a name to a {@link Type} for clearer error messages and help text.\n *\n * @param name - Name to use for the type.\n * @param type - Base type to name.\n * @returns A {@link Type} with the given name.\n */\nexport function typeRenamed<Value>(\n type: Type<Value>,\n name: string,\n): Type<Value> {\n return {\n content: name,\n decoder: (input: string) => {\n return TypoError.tryWithContext(\n () => type.decoder(input),\n () =>\n new TypoText(\n new TypoString(\"from: \"),\n new TypoString(type.content, typoStyleLogic),\n ),\n );\n },\n };\n}\n\n/**\n * Creates a {@link Type} for filesystem paths with optional existence checks.\n * @param checks - Optional checks for path existence and type (file/directory).\n * @returns A {@link Type}`<string>` representing the path.\n */\nexport function typePath(\n name?: string,\n checks?: { checkSyncExistAs?: \"file\" | \"directory\" | \"anything\" },\n): Type<string> {\n return {\n content: name ?? \"path\",\n decoder(input: string) {\n if (input.length === 0) {\n throw new Error(`Path cannot be empty`);\n }\n if (input.includes(\"\\0\")) {\n throw new Error(`Path cannot contain null characters`);\n }\n if (checks?.checkSyncExistAs !== undefined) {\n const stats = statSync(input);\n const preview = stats.isDirectory()\n ? \"directory\"\n : stats.isFile()\n ? \"file\"\n : \"unknown\";\n if (checks.checkSyncExistAs === \"file\" && !stats.isFile()) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Expected a 'file' but found '${preview}': `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n if (checks.checkSyncExistAs === \"directory\" && !stats.isDirectory()) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Expected a 'directory' but found '${preview}': `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n }\n return input;\n },\n };\n}\n\n/**\n * Creates a {@link Type}`<string>` that only accepts a fixed set of values.\n * Out-of-set inputs throw {@link TypoError} listing up to 5 valid options.\n *\n * @param name - Name shown in help and errors.\n * @param values - Ordered list of accepted values.\n * @returns A {@link Type}`<string>`.\n *\n * @example\n * ```ts\n * const typeEnv = typeChoice(\"environment\", [\"dev\", \"staging\", \"prod\"]);\n * typeEnv.decoder(\"prod\") // → \"prod\"\n * typeEnv.decoder(\"unknown\") // throws TypoError: Invalid value: \"unknown\" (expected one of: \"dev\" | \"staging\" | \"prod\")\n * ```\n */\nexport function typeChoice<const Value extends string>(\n name: string,\n values: Array<Value>,\n caseSensitive: boolean = false,\n): Type<Value> {\n const normalize = caseSensitive\n ? (s: string) => s\n : (s: string) => s.toLowerCase();\n const valueMap = new Map(values.map((value) => [normalize(value), value]));\n return {\n content: name,\n decoder(input: string) {\n const normalized = normalize(input);\n const original = valueMap.get(normalized);\n if (original !== undefined) {\n return original;\n }\n const valuesPreview = [];\n for (const value of values) {\n if (valuesPreview.length >= 5) {\n valuesPreview.push(new TypoString(`...`));\n break;\n }\n if (valuesPreview.length > 0) {\n valuesPreview.push(new TypoString(` | `));\n }\n valuesPreview.push(new TypoString(`\"${value}\"`, typoStyleQuote));\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Invalid value: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n new TypoString(` (expected one of: `),\n ...valuesPreview,\n new TypoString(`)`),\n ),\n );\n },\n };\n}\n\n/**\n * Splits a delimited string into a typed tuple.\n * Each part is decoded by the corresponding element type; wrong count or decode failure throws {@link TypoError}.\n *\n * @typeParam Elements - Tuple of decoded value types (inferred from `elementTypes`).\n *\n * @param elementTypes - One {@link Type} per tuple element, in order.\n * @param separator - Delimiter (default `\",\"`).\n * @returns A {@link Type}`<Elements>`.\n *\n * @example\n * ```ts\n * const typePoint = typeTuple([typeNumber(\"x\"), typeNumber(\"y\")]);\n * typePoint.decoder(\"3.14,2.71\") // → [3.14, 2.71]\n * typePoint.decoder(\"1,2,3\") // → [1, 2]\n * typePoint.decoder(\"x,2\") // throws TypoError: at 0: Number: Unable to parse: \"x\"\n * ```\n */\nexport function typeTuple<const Elements extends Array<any>>(\n elementTypes: { [K in keyof Elements]: Type<Elements[K]> },\n separator: string = \",\",\n): Type<Elements> {\n return {\n content: elementTypes\n .map((elementType) => elementType.content)\n .join(separator),\n decoder(input: string) {\n const splits = input.split(separator, elementTypes.length);\n if (splits.length !== elementTypes.length) {\n throw new TypoError(\n new TypoText(\n new TypoString(`Found ${splits.length} splits: `),\n new TypoString(`Expected ${elementTypes.length} splits from: `),\n new TypoString(`\"${input}\"`, typoStyleQuote),\n ),\n );\n }\n return splits.map((split, index) => {\n const elementType = elementTypes[index]!;\n return TypoError.tryWithContext(\n () => elementType.decoder(split),\n () =>\n new TypoText(\n new TypoString(`at ${index}: `),\n new TypoString(elementType.content, typoStyleLogic),\n ),\n );\n }) as Elements;\n },\n };\n}\n\n/**\n * Splits a delimited string into a typed array.\n * Each part is decoded by `elementType`; failed decodes throw {@link TypoError}.\n * Note: splitting an empty string yields one empty element — prefer {@link optionRepeatable} for a zero-default.\n *\n * @typeParam Value - Element type produced by `elementType.decoder`.\n *\n * @param elementType - Decoder applied to each element.\n * @param separator - Delimiter (default `\",\"`).\n * @returns A {@link Type}`<Array<Value>>`.\n *\n * @example\n * ```ts\n * const typeNumbers = typeList(typeNumber);\n * typeNumbers.decoder(\"1,2,3\") // → [1, 2, 3]\n * typeNumbers.decoder(\"1,x,3\") // throws TypoError: at 1: Number: Unable to parse: \"x\"\n *\n * const typePaths = typeList(typePath(), \":\");\n * typePaths.decoder(\"/usr/bin:/usr/local/bin\") // → [\"/usr/bin\", \"/usr/local/bin\"]\n * ```\n */\nexport function typeList<Value>(\n elementType: Type<Value>,\n separator: string = \",\",\n): Type<Array<Value>> {\n return {\n content: `${elementType.content}[${separator}${elementType.content}]...`,\n decoder(input: string) {\n const splits = input.split(separator);\n return splits.map((split, index) =>\n TypoError.tryWithContext(\n () => elementType.decoder(split),\n () =>\n new TypoText(\n new TypoString(`at ${index}: `),\n new TypoString(elementType.content, typoStyleLogic),\n ),\n ),\n );\n },\n };\n}\n","import { ReaderOptionParsing, ReaderArgs as ReaderOptions } from \"./Reader\";\nimport { Type, typeBoolean } from \"./Type\";\nimport {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleLogic,\n typoStyleUserInput,\n TypoText,\n} from \"./Typo\";\nimport { UsageOption } from \"./Usage\";\n\n/**\n * A CLI option. Created with {@link optionFlag}, {@link optionSingleValue},\n * or {@link optionRepeatable}.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type Option<Value> = {\n /**\n * Returns metadata for the `Options:` section.\n */\n generateUsage(): UsageOption;\n /**\n * Registers the option on `readerOptions` and returns an {@link OptionDecoder}.\n */\n registerAndMakeDecoder(readerOptions: ReaderOptions): OptionDecoder<Value>;\n};\n\n/**\n * Produced by {@link Option.registerAndMakeDecoder}.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type OptionDecoder<Value> = {\n /**\n * Returns the decoded option value.\n *\n * @throws {@link TypoError} if decoding failed.\n */\n getAndDecodeValue(): Value;\n};\n\n/**\n * Creates a boolean flag option (`--verbose`, optionally `--flag=no`).\n *\n * Parsing: absent → default value; `--flag` / `--flag=yes` → `true`; `--flag=no` → `false`;\n * specified more than once → throws {@link TypoError}.\n *\n * @param definition.long - Long-form name (without `--`).\n * @param definition.short - Short-form name (without `-`).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.aliases - Additional names.\n * @param definition.default - Default value when absent.\n * @returns An {@link Option}`<boolean>`.\n *\n * @example\n * ```ts\n * const verboseFlag = optionFlag({\n * long: \"verbose\",\n * short: \"v\",\n * description: \"Enable verbose output\",\n * });\n * // Usage:\n * // my-cli → false\n * // my-cli --verbose → true\n * // my-cli --verbose=yes → true\n * // my-cli -v=no → false\n * ```\n */\nexport function optionFlag(definition: {\n long: string;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<string>; shorts?: Array<string> };\n default?: boolean;\n}): Option<boolean> {\n const type = typeBoolean(\"value\");\n const { long, short, description, hint, aliases } = definition;\n return {\n generateUsage() {\n return { short, long, annotation: \"[=no]\", description, hint };\n },\n registerAndMakeDecoder(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n long,\n short,\n aliasesLongs: aliases?.longs,\n aliasesShorts: aliases?.shorts,\n parsing: { consumeShortGroup: false, consumeNextArg: () => false },\n });\n return {\n getAndDecodeValue() {\n const optionResults = readerOptions.getOptionValues(key);\n if (optionResults.length > 1) {\n throwSetMultipleTimesError(long);\n }\n if (optionResults.length === 0) {\n return definition.default === undefined\n ? false\n : definition.default;\n }\n const positiveResult = optionResults[0]!;\n const value =\n positiveResult.inlined === null ? \"true\" : positiveResult.inlined;\n return decodeValue({ long, short, type, input: value });\n },\n };\n },\n };\n}\n\n/**\n * Creates an option that accepts exactly one value (e.g. `--output dist/`).\n *\n * Parsing: absent → `defaultValue()`; once → decoded with `type`; more than once → {@link TypoError}.\n * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.\n *\n * @typeParam Value - Type produced by the decoder.\n *\n * @param definition.long - Long-form name (without `--`).\n * @param definition.short - Short-form name (without `-`).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.aliases - Additional names.\n * @param definition.type - Decoder for the raw string value.\n * @param definition.valueWhenNotDefined - Default value when the option is not specified at all.\n * @param definition.valueWhenNotInlined - Default value when the option is specified without an inline value (e.g. `--option` or `-o`).\n * @returns An {@link Option}`<Value>`.\n *\n * @example\n * ```ts\n * const outputOption = optionSingleValue({\n * long: \"output\",\n * short: \"o\",\n * type: typePath(),\n * description: \"Output directory\",\n * valueWhenNotDefined: () => \"dist\",\n * });\n * // Usage:\n * // my-cli → \"dist\"\n * // my-cli --output folder → \"folder\"\n * // my-cli -o folder → \"folder\"\n * ```\n */\nexport function optionSingleValue<Value>(definition: {\n long: string;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<string>; shorts?: Array<string> };\n type: Type<Value>;\n defaultWhenNotDefined: () => Value;\n defaultWhenNotInlined?: () => Value;\n}): Option<Value> {\n const { long, short, description, hint, aliases, type } = definition;\n const label = `<${type.content}>`;\n return {\n generateUsage() {\n return { short, long, label, description, hint };\n },\n registerAndMakeDecoder(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n long,\n short,\n aliasesLongs: aliases?.longs,\n aliasesShorts: aliases?.shorts,\n parsing: {\n consumeShortGroup: true,\n consumeNextArg(inlined, separated) {\n if (definition.defaultWhenNotInlined !== undefined) {\n return false;\n }\n return inlined === null && separated.length === 0;\n },\n },\n });\n return {\n getAndDecodeValue() {\n const optionResults = readerOptions.getOptionValues(key);\n if (optionResults.length > 1) {\n throwSetMultipleTimesError(long);\n }\n const optionResult = optionResults[0];\n if (optionResult === undefined) {\n try {\n return definition.defaultWhenNotDefined();\n } catch (error) {\n throwFailedToGetDefaultValueError(long, error, \"not set\");\n }\n }\n if (optionResult.inlined) {\n const inlined = optionResult.inlined;\n return decodeValue({ long, short, label, type, input: inlined });\n }\n if (definition.defaultWhenNotInlined !== undefined) {\n try {\n return definition.defaultWhenNotInlined();\n } catch (error) {\n throwFailedToGetDefaultValueError(long, error, \"not inlined\");\n }\n }\n const separated = optionResult.separated[0]!;\n return decodeValue({ long, short, label, type, input: separated });\n },\n };\n },\n };\n}\n\n/**\n * Creates an option that collects every occurrence into an array (e.g. `--file a.ts --file b.ts`).\n *\n * Parsing: absent → `[]`; N occurrences → array of N decoded values in order.\n * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.\n *\n * @typeParam Value - Type produced by the decoder for each occurrence.\n *\n * @param definition.long - Long-form name (without `--`).\n * @param definition.short - Short-form name (without `-`).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.aliases - Additional names.\n * @param definition.type - Decoder applied to each raw string value.\n * @returns An {@link Option}`<Array<Value>>`.\n *\n * @example\n * ```ts\n * const filesOption = optionRepeatable({\n * long: \"file\",\n * short: \"f\",\n * type: typeString,\n * label: \"PATH\",\n * description: \"Input file (may be repeated)\",\n * });\n * // Usage: my-cli --file a.ts --file b.ts → [\"a.ts\", \"b.ts\"]\n * ```\n */\nexport function optionRepeatable<Value>(definition: {\n long: string;\n short?: string;\n description?: string;\n hint?: string;\n aliases?: { longs?: Array<string>; shorts?: Array<string> };\n type: Type<Value>;\n}): Option<Array<Value>> {\n const { long, short, description, hint, aliases, type } = definition;\n const label = `<${type.content}>`;\n return {\n generateUsage() {\n return { short, long, label, annotation: \" [*]\", description, hint };\n },\n registerAndMakeDecoder(readerOptions: ReaderOptions) {\n const key = registerOption(readerOptions, {\n long,\n short,\n aliasesLongs: aliases?.longs,\n aliasesShorts: aliases?.shorts,\n parsing: {\n consumeShortGroup: true,\n consumeNextArg: (inlined, separated) =>\n inlined === null && separated.length === 0,\n },\n });\n return {\n getAndDecodeValue() {\n const optionResults = readerOptions.getOptionValues(key);\n return optionResults.map((optionResult) => {\n const input = optionResult.inlined ?? optionResult.separated[0]!;\n return decodeValue({ long, short, label, type, input });\n });\n },\n };\n },\n };\n}\n\nfunction decodeValue<Value>(params: {\n long: string;\n short?: string | undefined;\n label?: string | undefined;\n type: Type<Value>;\n input: string;\n}): Value {\n return TypoError.tryWithContext(\n () => params.type.decoder(params.input),\n () => {\n const text = new TypoText();\n if (params.short) {\n text.push(new TypoString(`-${params.short}`, typoStyleConstants));\n text.push(new TypoString(`, `));\n }\n text.push(new TypoString(`--${params.long}`, typoStyleConstants));\n if (params.label) {\n text.push(new TypoString(`: `));\n text.push(new TypoString(params.label, typoStyleUserInput));\n } else {\n text.push(new TypoString(`: `));\n text.push(new TypoString(params.type.content, typoStyleLogic));\n }\n return text;\n },\n );\n}\n\nfunction registerOption(\n readerOptions: ReaderOptions,\n definition: {\n long: string;\n short: undefined | string;\n aliasesLongs: undefined | Array<string>;\n aliasesShorts: undefined | Array<string>;\n parsing: ReaderOptionParsing;\n },\n) {\n const { long, short, aliasesLongs, aliasesShorts, parsing } = definition;\n const longs = long ? [long] : [];\n if (aliasesLongs) {\n longs.push(...aliasesLongs);\n }\n const shorts = short ? [short] : [];\n if (aliasesShorts) {\n shorts.push(...aliasesShorts);\n }\n return readerOptions.registerOption({ longs, shorts, parsing });\n}\n\nfunction throwSetMultipleTimesError(long: string): never {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${long}`, typoStyleConstants),\n new TypoString(`: Must not be set multiple times`),\n ),\n );\n}\n\nfunction throwFailedToGetDefaultValueError(\n long: string,\n error: unknown,\n context: string,\n): never {\n throw new TypoError(\n new TypoText(\n new TypoString(`--${long}`, typoStyleConstants),\n new TypoString(`: Failed to get default value (${context})`),\n ),\n error,\n );\n}\n","import { ReaderPositionals } from \"./Reader\";\nimport { Type } from \"./Type\";\nimport { TypoError, TypoString, typoStyleUserInput, TypoText } from \"./Typo\";\nimport { UsagePositional } from \"./Usage\";\n\n/**\n * A positional argument. Created with {@link positionalRequired}, {@link positionalOptional},\n * or {@link positionalVariadics}.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type Positional<Value> = {\n /**\n * Returns metadata for the `Positionals:` section.\n */\n generateUsage(): UsagePositional;\n /**\n * Consumes the next positional token from `readerPositionals`.\n * Returns a decoder that produces the final value.\n */\n consumeAndMakeDecoder(\n readerPositionals: ReaderPositionals,\n ): PositionalDecoder<Value>;\n};\n\n/**\n * Produced by {@link Positional.consumeAndMakeDecoder}.\n *\n * @typeParam Value - Decoded value type.\n */\nexport type PositionalDecoder<Value> = {\n /**\n * Returns the decoded positional value.\n *\n * @throws {@link TypoError} if decoding failed.\n */\n decodeValue(): Value;\n};\n\n/**\n * Creates a required positional — missing token throws {@link TypoError}.\n *\n * @typeParam Value - Type produced by the decoder.\n *\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.type - Decoder for the raw token.\n * @returns A {@link Positional}`<Value>`.\n *\n * @example\n * ```ts\n * const namePositional = positionalRequired({\n * type: type(\"name\"),\n * description: \"The name to greet\",\n * });\n * // Usage:\n * // my-cli Alice → \"Alice\"\n * ```\n */\nexport function positionalRequired<Value>(definition: {\n description?: string;\n hint?: string;\n type: Type<Value>;\n}): Positional<Value> {\n const { description, hint, type } = definition;\n const label = `<${type.content}>`;\n return {\n generateUsage() {\n return { description, hint, label };\n },\n consumeAndMakeDecoder(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n if (positional === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Is required, but was not provided`),\n ),\n );\n }\n return {\n decodeValue() {\n return decodeValue(label, definition.type, positional);\n },\n };\n },\n };\n}\n\n/**\n * Creates an optional positional — absent token falls back to `default()`.\n *\n * @typeParam Value - Type produced by the decoder (or the default).\n *\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.type - Decoder for the raw token.\n * @param definition.default - Value when absent. Throw to make it required.\n * @returns A {@link Positional}`<Value>`.\n *\n * @example\n * ```ts\n * const greeteePositional = positionalOptional({\n * type: type(\"name\"),\n * description: \"Name to greet (default: world)\",\n * default: () => \"world\",\n * });\n * // Usage:\n * // my-cli → \"world\"\n * // my-cli Alice → \"Alice\"\n * ```\n */\nexport function positionalOptional<Value>(definition: {\n description?: string;\n hint?: string;\n type: Type<Value>;\n default: () => Value;\n}): Positional<Value> {\n const { description, hint, type } = definition;\n const label = `[${type.content}]`;\n return {\n generateUsage() {\n return { description, hint, label };\n },\n consumeAndMakeDecoder(readerPositionals: ReaderPositionals) {\n const positional = readerPositionals.consumePositional();\n return {\n decodeValue() {\n if (positional === undefined) {\n try {\n return definition.default();\n } catch (error) {\n throwsWhenFailedToGetDefault(label);\n }\n }\n return decodeValue(label, definition.type, positional);\n },\n };\n },\n };\n}\n\n/**\n * Creates a variadic positional that collects zero or more remaining tokens into an array.\n * Optionally stops at `endDelimiter` (consumed, not included).\n *\n * @typeParam Value - Type produced by the decoder for each token.\n *\n * @param definition.endDelimiter - Sentinel token that stops collection (consumed, not included).\n * @param definition.description - Help text.\n * @param definition.hint - Short note shown in parentheses.\n * @param definition.type - Decoder applied to each token.\n * @returns A {@link Positional}`<Array<Value>>`.\n *\n * @example\n * ```ts\n * const filesPositional = positionalVariadics({\n * type: typePath(),\n * description: \"Files to process\",\n * });\n * // Usage:\n * // my-cli → []\n * // my-cli a.ts b.ts c.ts → [\"a.ts\", \"b.ts\", \"c.ts\"]\n * ```\n */\nexport function positionalVariadics<Value>(definition: {\n endDelimiter?: string;\n description?: string;\n hint?: string;\n type: Type<Value>;\n}): Positional<Array<Value>> {\n const { description, hint, type } = definition;\n const labelSingle = `[${type.content}]`;\n const labelMultiple =\n `${labelSingle}...` +\n (definition.endDelimiter ? ` [\"${definition.endDelimiter}\"]` : \"\");\n return {\n generateUsage() {\n return { description, hint, label: labelMultiple };\n },\n consumeAndMakeDecoder(readerPositionals: ReaderPositionals) {\n const positionals = new Array<string>();\n while (true) {\n const positional = readerPositionals.consumePositional();\n if (\n positional === undefined ||\n positional === definition.endDelimiter\n ) {\n break;\n }\n positionals.push(positional);\n }\n return {\n decodeValue() {\n return positionals.map((positional) =>\n decodeValue(labelSingle, definition.type, positional),\n );\n },\n };\n },\n };\n}\n\nfunction decodeValue<Value>(\n label: string,\n type: Type<Value>,\n input: string,\n): Value {\n return TypoError.tryWithContext(\n () => type.decoder(input),\n () => new TypoText(new TypoString(label, typoStyleUserInput)),\n );\n}\n\nfunction throwsWhenFailedToGetDefault(label: string): never {\n throw new TypoError(\n new TypoText(\n new TypoString(label, typoStyleUserInput),\n new TypoString(`: Failed to get default value`),\n ),\n );\n}\n","import {\n TypoError,\n TypoString,\n typoStyleConstants,\n typoStyleQuote,\n TypoText,\n} from \"./Typo\";\n\n/**\n * Opaque key returned by {@link ReaderArgs.registerOption}.\n */\nexport type ReaderOptionKey = (string | { __brand: \"ReaderOptionKey\" }) & {\n __brand: \"ReaderOptionKey\";\n};\n\n/**\n * Parsing behaviour for a registered option, passed to {@link ReaderArgs.registerOption}.\n */\nexport type ReaderOptionParsing = {\n consumeShortGroup: boolean; // TODO - this doesnt matter when no short option\n consumeNextArg: (\n inlined: string | null,\n separated: Array<string>,\n nextArg: string | undefined,\n ) => boolean;\n};\n\n/**\n * Result of parsing an option, including its inlined value and any following separated values.\n */\nexport type ReaderOptionValue = {\n inlined: string | null;\n separated: Array<string>;\n};\n\n/**\n * Option registration/query interface. Subset of {@link ReaderArgs}.\n */\nexport type ReaderOptions = {\n /**\n * Registers an option; all `longs` and `shorts` share the same key.\n *\n * @param definition.longs - Long-form names (without `--`).\n * @param definition.shorts - Short-form names (without `-`).\n * @param definition.parsing - Parsing behaviour.\n * @returns A {@link ReaderOptionKey} for later retrieval.\n * @throws `Error` if a name is already registered or short names overlap.\n */\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n parsing: ReaderOptionParsing;\n }): ReaderOptionKey;\n /**\n * Returns all values collected for `key`.\n */\n getOptionValues(key: ReaderOptionKey): Array<ReaderOptionValue>;\n};\n\n/**\n * Positional consumption interface. Subset of {@link ReaderArgs}.\n */\nexport type ReaderPositionals = {\n /**\n * Returns the next positional token, parsing intervening options as side-effects.\n *\n * @returns The next positional, or `undefined` when exhausted.\n * @throws {@link TypoError} on an unrecognised option.\n */\n consumePositional(): string | undefined;\n};\n\n/**\n * Core argument parser: converts raw CLI tokens into named options and positionals.\n * Options must be registered before {@link ReaderArgs.consumePositional} is called.\n *\n * Supported syntax: `--name`, `--name value`, `--name=value`,\n * `-n`, `-n value`, `-nvalue`, `-abc` (stacked), `--` (end-of-options).\n *\n * Created internally by {@link runAndExit}; exposed for advanced / custom runners.\n */\nexport class ReaderArgs {\n #args: ReadonlyArray<string>;\n #parsedIndex: number;\n #parsedDouble: boolean;\n #optionContextByLong: Map<string, ReaderOptionContext>;\n #optionContextByShort: Map<string, ReaderOptionContext>;\n #optionContextByKey: Map<ReaderOptionKey, ReaderOptionContext>;\n\n /**\n * @param args - Raw CLI tokens (e.g. `process.argv.slice(2)`). Not mutated.\n */\n constructor(args: ReadonlyArray<string>) {\n this.#args = args;\n this.#parsedIndex = 0;\n this.#parsedDouble = false;\n this.#optionContextByLong = new Map();\n this.#optionContextByShort = new Map();\n this.#optionContextByKey = new Map();\n }\n\n /**\n * Registers an option; all `longs` and `shorts` share the same key.\n * Short names must not be prefixes of one another.\n *\n * @param definition.longs - Long-form names (without `--`).\n * @param definition.shorts - Short-form names (without `-`).\n * @param definition.parsing - Parsing behaviour.\n * @returns A {@link ReaderOptionKey} for {@link ReaderArgs.getOptionValues}.\n * @throws `Error` if any name is already registered or short names overlap.\n */\n registerOption(definition: {\n longs: Array<string>;\n shorts: Array<string>;\n parsing: ReaderOptionParsing;\n }) {\n const key = [\n ...definition.longs.map((long) => `--${long}`),\n ...definition.shorts.map((short) => `-${short}`),\n ].join(\", \") as ReaderOptionKey;\n for (const long of definition.longs) {\n if (!this.#isValidOptionName(long)) {\n throw new Error(`Invalid option name: --${long}`);\n }\n if (this.#optionContextByLong.has(long)) {\n throw new Error(`Option already registered: --${long}`);\n }\n }\n for (const short of definition.shorts) {\n if (!this.#isValidOptionName(short)) {\n throw new Error(`Invalid option name: -${short}`);\n }\n if (this.#optionContextByShort.has(short)) {\n throw new Error(`Option already registered: -${short}`);\n }\n for (let i = 0; i < short.length; i++) {\n const shortSlice = short.slice(0, i);\n if (this.#optionContextByShort.has(shortSlice)) {\n throw new Error(\n `Option -${short} overlap with shorter option: -${shortSlice}`,\n );\n }\n }\n for (const shortOther of this.#optionContextByShort.keys()) {\n if (shortOther.startsWith(short)) {\n throw new Error(\n `Option -${short} overlap with longer option: -${shortOther}`,\n );\n }\n }\n }\n const optionContext = {\n parsing: definition.parsing,\n results: new Array<ReaderOptionValue>(),\n };\n for (const long of definition.longs) {\n this.#optionContextByLong.set(long, optionContext);\n }\n for (const short of definition.shorts) {\n this.#optionContextByShort.set(short, optionContext);\n }\n this.#optionContextByKey.set(key, optionContext);\n return key;\n }\n\n /**\n * Returns all values collected for `key`.\n *\n * @param key - Key from {@link ReaderArgs.registerOption}.\n * @returns One entry per occurrence.\n * @throws `Error` if `key` was not registered.\n */\n getOptionValues(key: ReaderOptionKey): Array<ReaderOptionValue> {\n const optionContext = this.#optionContextByKey.get(key);\n if (optionContext === undefined) {\n throw new Error(`Unregistered option: ${key}`);\n }\n return optionContext.results;\n }\n\n /**\n * Returns the next positional token; parses intervening options as a side-effect.\n * All tokens after `--` are treated as positionals.\n *\n * @returns The next positional, or `undefined` when exhausted.\n * @throws {@link TypoError} on an unrecognised option.\n */\n consumePositional(): string | undefined {\n while (true) {\n const arg = this.#consumeArg();\n if (arg === undefined) {\n return undefined;\n }\n if (!this.#tryConsumeAsOption(arg)) {\n return arg;\n }\n }\n }\n\n #consumeArg(): string | undefined {\n const arg = this.#args[this.#parsedIndex];\n if (arg === undefined) {\n return undefined;\n }\n this.#parsedIndex++;\n if (!this.#parsedDouble) {\n if (arg === \"--\") {\n this.#parsedDouble = true;\n return this.#consumeArg();\n }\n }\n return arg;\n }\n\n #tryConsumeAsOption(arg: string): boolean {\n if (this.#parsedDouble) {\n return false;\n }\n if (arg.startsWith(\"--\")) {\n const valueIndexStart = arg.indexOf(\"=\");\n if (valueIndexStart === -1) {\n this.#consumeOptionLong(arg.slice(2), null);\n } else {\n this.#consumeOptionLong(\n arg.slice(2, valueIndexStart),\n arg.slice(valueIndexStart + 1),\n );\n }\n return true;\n }\n if (arg.startsWith(\"-\")) {\n let shortIndexStart = 1;\n let shortIndexEnd = 2;\n while (shortIndexEnd <= arg.length) {\n const short = arg.slice(shortIndexStart, shortIndexEnd);\n const optionContext = this.#optionContextByShort.get(short);\n if (optionContext !== undefined) {\n const rest = arg.slice(shortIndexEnd);\n if (this.#tryConsumeOptionShort(optionContext, short, rest)) {\n return true;\n }\n shortIndexStart = shortIndexEnd;\n }\n shortIndexEnd++;\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Unexpected unknown option(s): `),\n new TypoString(`-${arg.slice(shortIndexStart)}`, typoStyleQuote),\n ),\n );\n }\n return false;\n }\n\n #consumeOptionLong(long: string, inlined: string | null): void {\n const constant = `--${long}`;\n const optionContext = this.#optionContextByLong.get(long);\n if (optionContext !== undefined) {\n return this.#consumeOptionValues(optionContext, constant, inlined);\n }\n throw new TypoError(\n new TypoText(\n new TypoString(`Unexpected unknown option: `),\n new TypoString(constant, typoStyleQuote),\n ),\n );\n }\n\n #tryConsumeOptionShort(\n optionContext: ReaderOptionContext,\n short: string,\n rest: string,\n ): boolean {\n const constant = `-${short}`;\n if (rest.startsWith(\"=\")) {\n this.#consumeOptionValues(optionContext, constant, rest.slice(1));\n return true;\n }\n if (rest.length === 0) {\n this.#consumeOptionValues(optionContext, constant, null);\n return true;\n }\n if (optionContext.parsing.consumeShortGroup) {\n this.#consumeOptionValues(optionContext, constant, rest);\n return true;\n }\n this.#consumeOptionValues(optionContext, constant, null);\n return false;\n }\n\n #consumeOptionValues(\n optionContext: ReaderOptionContext,\n constant: string,\n inlined: string | null,\n ) {\n const separated = new Array<string>();\n while (\n optionContext.parsing.consumeNextArg(\n inlined,\n separated,\n this.#args[this.#parsedIndex],\n )\n ) {\n separated.push(this.#consumeOptionValue(constant));\n }\n optionContext.results.push({ inlined, separated });\n }\n\n #consumeOptionValue(constant: string): string {\n const arg = this.#consumeArg();\n if (arg === undefined) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got end of input`),\n ),\n );\n }\n if (this.#parsedDouble) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value before `),\n new TypoString(`\"--\"`, typoStyleQuote),\n ),\n );\n }\n // TODO - is that weird, could a valid value start with dash ?\n if (arg.startsWith(\"-\")) {\n throw new TypoError(\n new TypoText(\n new TypoString(constant, typoStyleConstants),\n new TypoString(`: Requires a value, but got: `),\n new TypoString(`\"${arg}\"`, typoStyleQuote),\n ),\n );\n }\n return arg;\n }\n\n #isValidOptionName(name: string): boolean {\n return name.length > 0 && !name.includes(\"=\") && !name.includes(\"\\0\");\n }\n}\n\ntype ReaderOptionContext = {\n parsing: ReaderOptionParsing;\n results: Array<ReaderOptionValue>;\n};\n","import { CommandInformation } from \"./Command\";\nimport {\n TypoGrid,\n TypoString,\n typoStyleConstants,\n typoStyleLogic,\n typoStyleRegularStrong,\n typoStyleRegularWeaker,\n typoStyleTitle,\n typoStyleUserInput,\n TypoSupport,\n TypoText,\n} from \"./Typo\";\n\n/**\n * Usage model. Produced by {@link CommandDecoder.generateUsage}, consumed by {@link usageToStyledLines}.\n */\nexport type UsageCommand = {\n /**\n * Segments of the usage line\n */\n segments: Array<{ positional: string } | { subcommand: string }>;\n /**\n * Command metadata.\n */\n information: CommandInformation;\n /**\n * Positionals in declaration order.\n */\n positionals: Array<UsagePositional>;\n /**\n * Subcommands, populated when none was selected.\n */\n subcommands: Array<UsageSubcommand>;\n /**\n * Options in registration order.\n */\n options: Array<UsageOption>;\n};\n\n/**\n * Positional metadata for the `Positionals:` section of help.\n */\nexport type UsagePositional = {\n /**\n * Help text.\n */\n description?: string | undefined;\n /**\n * Short note shown in parentheses.\n */\n hint?: string | undefined;\n /**\n * Placeholder label shown in the usage line and the `Positionals:` section.\n */\n label: string;\n};\n\n/**\n * Entry in the `Subcommands:` section.\n */\nexport type UsageSubcommand = {\n /**\n * Token the user types (e.g. `\"deploy\"`).\n */\n name: string;\n /**\n * From {@link CommandInformation.description}.\n */\n description?: string | undefined;\n /**\n * From {@link CommandInformation.hint}.\n */\n hint?: string | undefined;\n};\n\n/**\n * Option metadata for the `Options:` section of help.\n */\nexport type UsageOption = {\n /**\n * Short-form name without `-` (e.g. `\"v\"`).\n */\n short?: string | undefined;\n /**\n * Long-form name without `--` (e.g. `\"verbose\"`).\n */\n long: string;\n /**\n * Value placeholder in help (e.g. `\"<FILE>\"`).\n */\n label?: string | undefined;\n /**\n * Extra annotation appended to the option label in help.\n */\n annotation?: string | undefined;\n /**\n * Help text.\n */\n description?: string | undefined;\n /**\n * Short note shown in parentheses.\n */\n hint?: string | undefined;\n};\n\n/**\n * Converts a {@link UsageCommand} model into an array of styled lines ready to be\n * joined with `\"\\n\"` and printed to the terminal.\n *\n * The output format is:\n * ```\n * Usage: <cliName> [segments...]\n *\n * <description> (<hint>)\n * <detail lines...>\n *\n * Positionals:\n * <LABEL> <description> (<hint>)\n *\n * Subcommands:\n * <name> <description> (<hint>)\n *\n * Options:\n * -s, --long <LABEL><annotation> <description> (<hint>)\n *\n * Examples:\n * <description>\n * <command line>\n *\n * ```\n * Sections that have no entries are omitted. The trailing empty line is always included.\n *\n * Column alignment per section via {@link TypoGrid}.\n *\n * @param params.cliName - Program name for the usage line.\n * @param params.usage - From {@link CommandDecoder.generateUsage}.\n * @param params.typoSupport - Rendering mode.\n * @returns Styled lines; includes a trailing empty string.\n *\n * @example\n * ```ts\n * const lines = usageToStyledLines({\n * cliName: \"my-cli\",\n * usage: commandDecoder.generateUsage(),\n * typoSupport: TypoSupport.tty(),\n * });\n * process.stdout.write(lines.join(\"\\n\"));\n * ```\n */\nexport function usageToStyledLines(params: {\n cliName: string;\n usage: UsageCommand;\n typoSupport: TypoSupport;\n}) {\n const { cliName, usage, typoSupport } = params;\n\n const lines = new Array<string>();\n\n const segmentsText = new TypoText();\n segmentsText.push(textUsageHero(\"Usage:\"));\n segmentsText.push(textDelimiter(\" \"));\n segmentsText.push(textConstants(cliName));\n for (const segment of usage.segments) {\n segmentsText.push(textDelimiter(\" \"));\n if (\"positional\" in segment) {\n segmentsText.push(textUserInput(segment.positional));\n }\n if (\"subcommand\" in segment) {\n segmentsText.push(textConstants(segment.subcommand));\n }\n }\n lines.push(segmentsText.computeStyledString(typoSupport));\n\n lines.push(\"\");\n const introText = new TypoText();\n introText.push(textUsageText(usage.information.description));\n if (usage.information.hint) {\n introText.push(textDelimiter(\" \"));\n introText.push(textSubtleInfo(`(${usage.information.hint})`));\n }\n lines.push(introText.computeStyledString(typoSupport));\n for (const detail of usage.information.details ?? []) {\n const detailText = new TypoText();\n detailText.push(textSubtleInfo(detail));\n lines.push(detailText.computeStyledString(typoSupport));\n }\n\n if (usage.positionals.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Positionals:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const positionalUsage of usage.positionals) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textUserInput(positionalUsage.label)));\n typoGridRow.push(...createInformationals(positionalUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(...typoGrid.computeStyledLines(typoSupport));\n }\n\n if (usage.subcommands.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Subcommands:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const subcommandUsage of usage.subcommands) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n typoGridRow.push(new TypoText(textConstants(subcommandUsage.name)));\n typoGridRow.push(...createInformationals(subcommandUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(...typoGrid.computeStyledLines(typoSupport));\n }\n\n if (usage.options.length > 0) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Options:\").computeStyledString(typoSupport));\n const typoGrid = new TypoGrid();\n for (const optionUsage of usage.options) {\n const typoGridRow = new Array<TypoText>();\n typoGridRow.push(new TypoText(textDelimiter(\" \")));\n if (optionUsage.short) {\n typoGridRow.push(\n new TypoText(\n textConstants(`-${optionUsage.short}`),\n textDelimiter(\", \"),\n ),\n );\n } else {\n typoGridRow.push(new TypoText());\n }\n const longOptionText = new TypoText(\n textConstants(`--${optionUsage.long}`),\n );\n if (optionUsage.label) {\n longOptionText.push(textDelimiter(\" \"));\n longOptionText.push(textUserInput(optionUsage.label));\n }\n if (optionUsage.annotation) {\n longOptionText.push(textSubtleInfo(optionUsage.annotation));\n }\n typoGridRow.push(longOptionText);\n typoGridRow.push(...createInformationals(optionUsage));\n typoGrid.pushRow(typoGridRow);\n }\n lines.push(...typoGrid.computeStyledLines(typoSupport));\n }\n\n if (usage.information.examples) {\n lines.push(\"\");\n lines.push(textBlockTitle(\"Examples:\").computeStyledString(typoSupport));\n for (const example of usage.information.examples) {\n const exampleExplanationText = new TypoText();\n exampleExplanationText.push(textDelimiter(\" \"));\n exampleExplanationText.push(textSubtleInfo(`# ${example.explanation}`));\n lines.push(exampleExplanationText.computeStyledString(typoSupport));\n const commandLineText = new TypoText();\n commandLineText.push(textDelimiter(\" \"));\n commandLineText.push(textConstants(cliName));\n for (const commandArg of example.commandArgs) {\n commandLineText.push(textDelimiter(\" \"));\n if (typeof commandArg === \"string\") {\n commandLineText.push(commandArg);\n } else if (\"positional\" in commandArg) {\n commandLineText.push(textUserInput(commandArg.positional));\n } else if (\"subcommand\" in commandArg) {\n commandLineText.push(textConstants(commandArg.subcommand));\n } else if (\"option\" in commandArg) {\n const option = commandArg.option;\n if (\"short\" in option) {\n commandLineText.push(textConstants(`-${option.short}`));\n } else {\n commandLineText.push(textConstants(`--${option.long}`));\n }\n if (option.inlined !== undefined) {\n commandLineText.push(textSubtleInfo(\"=\"));\n commandLineText.push(textUserInput(option.inlined));\n }\n if (option.separated !== undefined) {\n for (const separatedValue of option.separated) {\n commandLineText.push(textDelimiter(\" \"));\n commandLineText.push(textUserInput(separatedValue));\n }\n }\n }\n }\n lines.push(commandLineText.computeStyledString(typoSupport));\n }\n }\n\n lines.push(\"\");\n return lines;\n}\n\nfunction createInformationals(usage: {\n description?: string | undefined;\n hint?: string | undefined;\n}): Array<TypoText> {\n const informationals = [];\n if (usage.description) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textUsefulInfo(usage.description));\n }\n if (usage.hint) {\n informationals.push(textDelimiter(\" \"));\n informationals.push(textSubtleInfo(`(${usage.hint})`));\n }\n if (informationals.length > 0) {\n return [new TypoText(textDelimiter(\" \"), ...informationals)];\n }\n return [];\n}\n\nfunction textUsageHero(value: string): TypoString {\n return new TypoString(value, typoStyleLogic);\n}\n\nfunction textUsageText(value: string): TypoString {\n return new TypoString(value, typoStyleRegularStrong);\n}\n\nfunction textUsefulInfo(value: string): TypoString {\n return new TypoString(value);\n}\n\nfunction textBlockTitle(value: string): TypoString {\n return new TypoString(value, typoStyleTitle);\n}\n\nfunction textSubtleInfo(value: string): TypoString {\n return new TypoString(value, typoStyleRegularWeaker);\n}\n\nfunction textConstants(value: string): TypoString {\n return new TypoString(value, typoStyleConstants);\n}\n\nfunction textUserInput(value: string): TypoString {\n return new TypoString(value, typoStyleUserInput);\n}\n\nfunction textDelimiter(value: string): TypoString {\n return new TypoString(value);\n}\n","import { Command, CommandDecoder } from \"./Command\";\nimport { optionFlag, optionSingleValue } from \"./Option\";\nimport { ReaderArgs } from \"./Reader\";\nimport { typeChoice } from \"./Type\";\nimport { TypoSupport } from \"./Typo\";\nimport { usageToStyledLines } from \"./Usage\";\n\n/**\n * Main entry point: parses CLI arguments, executes the matched command, and exits.\n * Handles `--help`, `--version`, usage-on-error, and exit codes.\n *\n * Exit codes:\n * - `0` on success / `--help` / `--version`\n * - `1` on parse error or execution error.\n *\n * @typeParam Context - Forwarded unchanged to the handler.\n *\n * @param cliName - Program name used in usage and `--version` output.\n * @param cliArgs - Raw arguments, typically `process.argv.slice(2)`.\n * @param context - Forwarded to the handler.\n * @param command - Root {@link Command}.\n * @param options.colorSetup - Configures color support; enables `--color` flag if set to `\"flag\"`.\n * @param options.usageOnHelp - Enables `--help` flag (default `true`).\n * @param options.usageOnError - Prints usage to stderr on parse error (default `true`).\n * @param options.buildVersion - Enables `--version`; prints `<cliName> <buildVersion>`.\n * @param options.onError - Custom handler for errors.\n * @param options.onExit - Overrides `process.exit`; useful for testing.\n *\n * @returns `Promise<never>` — always calls `onExit`.\n *\n * @example\n * ```ts\n * import { runAndExit, command, operation, positionalRequired, type } from \"cli-kiss\";\n *\n * const greetCommand = command(\n * { description: \"Greet someone\" },\n * operation(\n * { options: {}, positionals: [positionalRequired({ type: type(\"name\") })] },\n * async function (_ctx, { positionals: [name] }) {\n * console.log(`Hello, ${name}!`);\n * },\n * ),\n * );\n *\n * await runAndExit(\"greet\", process.argv.slice(2), undefined, greetCommand, {\n * buildVersion: \"1.0.0\",\n * });\n * ```\n */\nexport async function runAndExit<Context>(\n cliName: string,\n cliArgs: ReadonlyArray<string>,\n context: Context,\n command: Command<Context, void>,\n options?: {\n colorSetup?: \"flag\" | \"env\" | \"always\" | \"never\" | \"mock\" | undefined;\n usageOnHelp?: boolean | undefined;\n usageOnError?: boolean | undefined;\n buildVersion?: string | undefined;\n onError?: ((error: unknown) => void) | undefined;\n onExit?: ((code: number) => never) | undefined;\n },\n): Promise<never> {\n const readerArgs = new ReaderArgs(cliArgs);\n const preprocessors = new Array<\n (commandDecoder: CommandDecoder<Context, void>) => undefined | number\n >();\n let typoSupport = TypoSupport.none();\n const colorSetup = options?.colorSetup ?? \"flag\";\n if (colorSetup === \"flag\") {\n const colorOption = optionSingleValue<\"auto\" | \"always\" | \"never\" | \"mock\">(\n {\n long: \"color\",\n type: typeChoice(\"color-mode\", [\"auto\", \"always\", \"never\", \"mock\"]),\n defaultWhenNotDefined: () => \"auto\",\n defaultWhenNotInlined: () => \"always\",\n },\n ).registerAndMakeDecoder(readerArgs);\n preprocessors.push(() => {\n try {\n typoSupport = computeTypoSupport(colorOption.getAndDecodeValue());\n } catch (error) {\n typoSupport = TypoSupport.inferFromEnv();\n throw error;\n }\n return undefined;\n });\n } else {\n if (colorSetup === \"env\") {\n typoSupport = TypoSupport.inferFromEnv();\n } else {\n typoSupport = computeTypoSupport(colorSetup);\n }\n }\n if (options?.usageOnHelp ?? true) {\n const helpOption = optionFlag({ long: \"help\" }).registerAndMakeDecoder(\n readerArgs,\n );\n preprocessors.push((commandDecoder) => {\n if (!helpOption.getAndDecodeValue()) {\n return undefined;\n }\n console.log(computeUsageString(cliName, commandDecoder, typoSupport));\n return 0;\n });\n }\n if (options?.buildVersion) {\n const versionOption = optionFlag({\n long: \"version\",\n }).registerAndMakeDecoder(readerArgs);\n preprocessors.push(() => {\n if (!versionOption.getAndDecodeValue()) {\n return undefined;\n }\n console.log([cliName, options.buildVersion].join(\" \"));\n return 0;\n });\n }\n /*\n // TODO - handle completions ?\n readerArgs.registerFlag({\n key: \"completion\",\n shorts: [],\n longs: [\"completion\"],\n });\n */\n const commandDecoder = command.consumeAndMakeDecoder(readerArgs);\n while (true) {\n try {\n const positional = readerArgs.consumePositional();\n if (positional === undefined) {\n break;\n }\n } catch (_) {}\n }\n const onExit = options?.onExit ?? process.exit;\n try {\n for (const preprocessor of preprocessors) {\n const preprocessorResult = preprocessor(commandDecoder);\n if (preprocessorResult !== undefined) {\n return onExit(preprocessorResult);\n }\n }\n const commandInterpreter = commandDecoder.decodeAndMakeInterpreter();\n try {\n await commandInterpreter.executeWithContext(context);\n return onExit(0);\n } catch (executionError) {\n handleError(options?.onError, executionError, typoSupport);\n return onExit(1);\n }\n } catch (parsingError) {\n if (options?.usageOnError ?? true) {\n console.error(computeUsageString(cliName, commandDecoder, typoSupport));\n }\n handleError(options?.onError, parsingError, typoSupport);\n return onExit(1);\n }\n}\n\nfunction handleError(\n onError: ((error: unknown) => void) | undefined,\n error: unknown,\n typoSupport: TypoSupport,\n) {\n if (onError !== undefined) {\n onError(error);\n } else {\n console.error(typoSupport.computeStyledErrorMessage(error));\n }\n}\n\nfunction computeUsageString<Context, Result>(\n cliName: string,\n commandDecoder: CommandDecoder<Context, Result>,\n typoSupport: TypoSupport,\n) {\n return usageToStyledLines({\n cliName,\n usage: commandDecoder.generateUsage(),\n typoSupport,\n }).join(\"\\n\");\n}\n\nfunction computeTypoSupport(\n colorMode: \"auto\" | \"always\" | \"never\" | \"mock\",\n): TypoSupport {\n switch (colorMode) {\n case \"auto\":\n return TypoSupport.inferFromEnv();\n case \"always\":\n return TypoSupport.tty();\n case \"never\":\n return TypoSupport.none();\n case \"mock\":\n return TypoSupport.mock();\n }\n}\n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AO,CAAC,CACjB,CACF,OAASM,EAAc,CACrB,OAAIvB,GAAS,cAAgB,KAC3B,QAAQ,MAAMe,GAAmBnB,EAASkB,EAAgBV,CAAW,CAAC,EAExEkB,GAAYtB,GAAS,QAASuB,EAAcnB,CAAW,EAChDa,EAAO,CAAC,CACjB,CACF,CAEA,SAASK,GACPE,EACAb,EACAP,EACA,CACIoB,IAAY,OACdA,EAAQb,CAAK,EAEb,QAAQ,MAAMP,EAAY,0BAA0BO,CAAK,CAAC,CAE9D,CAEA,SAASI,GACPnB,EACAkB,EACAV,EACA,CACA,OAAOqB,GAAmB,CACxB,QAAA7B,EACA,MAAOkB,EAAe,cAAc,EACpC,YAAAV,CACF,CAAC,EAAE,KAAK;AAAA,CAAI,CACd,CAEA,SAASM,GACPgB,EACa,CACb,OAAQA,EAAW,CACjB,IAAK,OACH,OAAOrB,EAAY,aAAa,EAClC,IAAK,SACH,OAAOA,EAAY,IAAI,EACzB,IAAK,QACH,OAAOA,EAAY,KAAK,EAC1B,IAAK,OACH,OAAOA,EAAY,KAAK,CAC5B,CACF","names":["index_exports","__export","ReaderArgs","TypoError","TypoGrid","TypoString","TypoSupport","TypoText","command","commandChained","commandWithSubcommands","operation","optionFlag","optionRepeatable","optionSingleValue","positionalOptional","positionalRequired","positionalVariadics","runAndExit","type","typeBoolean","typeChoice","typeConverted","typeDatetime","typeInteger","typeList","typeNumber","typePath","typeRenamed","typeTuple","typeUrl","typoStyleConstants","typoStyleFailure","typoStyleLogic","typoStyleQuote","typoStyleRegularStrong","typoStyleRegularWeaker","typoStyleTitle","typoStyleUserInput","usageToStyledLines","__toCommonJS","typoStyleTitle","typoStyleLogic","typoStyleQuote","typoStyleFailure","typoStyleConstants","typoStyleUserInput","typoStyleRegularStrong","typoStyleRegularWeaker","_value","_typoStyle","TypoString","value","typoStyle","__privateAdd","__privateSet","typoSupport","__privateGet","_typoStrings","_TypoText","segments","typoPart","segment","typoString","t","length","TypoText","_typoRows","TypoGrid","cells","widths","styledLines","typoGridRow","typoGridColumnIndex","width","styledGridRow","typoGridCell","padding","_typoText","_TypoError","currentTypoText","source","typoText","thrower","context","error","TypoError","_kind","_TypoSupport","kind","readEnvVar","name","envForceColor","styledValue","fgColorCode","ttyCodeFgColors","bgColorCode","ttyCodeBgColors","boldCode","ttyCodeBold","dimCode","ttyCodeDim","italicCode","ttyCodeItalic","underlineCode","ttyCodeUnderline","strikethroughCode","ttyCodeStrikethrough","ttyCodeReset","fgColorPart","bgColorPart","boldPart","dimPart","italicPart","underlinePart","TypoSupport","command","information","operation","readerArgs","operationDecoder","endPositional","TypoError","TypoText","TypoString","typoStyleQuote","generateUsageLeaf","operationInterpreter","context","error","commandWithSubcommands","subcommands","subcommandName","typoStyleUserInput","subcommandInput","subcommandDecoder","subcommandUsage","currentUsage","subcommandInterpreter","name","subcommand","description","hint","commandChained","positionals","options","positional","operation","inputs","handler","optionsUsage","optionKey","optionInput","positionalsUsage","positionalInput","readerArgs","optionsDecoders","positionalsDecoders","optionsValues","positionalsValues","positionalDecoder","context","import_fs","typeBoolean","name","input","lower","booleanValuesTrue","booleanValuesFalse","TypoError","TypoText","TypoString","typoStyleQuote","typeDatetime","timestampMs","typeNumber","parsed","typeInteger","typeUrl","type","typeConverted","before","mapper","typoStyleLogic","typeRenamed","typePath","checks","stats","preview","typeChoice","values","caseSensitive","normalize","valueMap","value","normalized","original","valuesPreview","typeTuple","elementTypes","separator","elementType","splits","split","index","typeList","optionFlag","definition","type","typeBoolean","long","short","description","hint","aliases","readerOptions","key","registerOption","optionResults","throwSetMultipleTimesError","positiveResult","value","decodeValue","optionSingleValue","label","inlined","separated","optionResult","error","throwFailedToGetDefaultValueError","optionRepeatable","input","params","TypoError","text","TypoText","TypoString","typoStyleConstants","typoStyleUserInput","typoStyleLogic","aliasesLongs","aliasesShorts","parsing","longs","shorts","context","positionalRequired","definition","description","hint","type","label","readerPositionals","positional","TypoError","TypoText","TypoString","typoStyleUserInput","decodeValue","positionalOptional","throwsWhenFailedToGetDefault","positionalVariadics","labelSingle","labelMultiple","positionals","input","_args","_parsedIndex","_parsedDouble","_optionContextByLong","_optionContextByShort","_optionContextByKey","_ReaderArgs_instances","consumeArg_fn","tryConsumeAsOption_fn","consumeOptionLong_fn","tryConsumeOptionShort_fn","consumeOptionValues_fn","consumeOptionValue_fn","isValidOptionName_fn","ReaderArgs","args","__privateAdd","__privateSet","definition","key","long","short","__privateMethod","__privateGet","i","shortSlice","shortOther","optionContext","arg","__privateWrapper","valueIndexStart","shortIndexStart","shortIndexEnd","rest","TypoError","TypoText","TypoString","typoStyleQuote","inlined","constant","separated","typoStyleConstants","name","usageToStyledLines","params","cliName","usage","typoSupport","lines","segmentsText","TypoText","textUsageHero","textDelimiter","textConstants","segment","textUserInput","introText","textUsageText","textSubtleInfo","detail","detailText","textBlockTitle","typoGrid","TypoGrid","positionalUsage","typoGridRow","createInformationals","subcommandUsage","optionUsage","longOptionText","example","exampleExplanationText","commandLineText","commandArg","option","separatedValue","informationals","textUsefulInfo","value","TypoString","typoStyleLogic","typoStyleRegularStrong","typoStyleTitle","typoStyleRegularWeaker","typoStyleConstants","typoStyleUserInput","runAndExit","cliName","cliArgs","context","command","options","readerArgs","ReaderArgs","preprocessors","typoSupport","TypoSupport","colorSetup","colorOption","optionSingleValue","typeChoice","computeTypoSupport","error","helpOption","optionFlag","commandDecoder","computeUsageString","versionOption","onExit","preprocessor","preprocessorResult","commandInterpreter","executionError","handleError","parsingError","onError","usageToStyledLines","colorMode"]}
|