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/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /**
2
- * Opaque key identifying a registered option within a {@link ReaderArgs} instance.
3
- * Returned by {@link ReaderArgs.registerOption}; passed to {@link ReaderArgs.getOptionValues}.
2
+ * Opaque key returned by {@link ReaderArgs.registerOption}.
4
3
  */
5
4
  type ReaderOptionKey = (string | {
6
5
  __brand: "ReaderOptionKey";
@@ -8,35 +7,44 @@ type ReaderOptionKey = (string | {
8
7
  __brand: "ReaderOptionKey";
9
8
  };
10
9
  /**
11
- * Option registration and query interface, implemented by {@link ReaderArgs}.
12
- * Exposed separately from {@link ReaderPositionals} so parsers depend only on what they need.
10
+ * Parsing behaviour for a registered option, passed to {@link ReaderArgs.registerOption}.
11
+ */
12
+ type ReaderOptionParsing = {
13
+ consumeShortGroup: boolean;
14
+ consumeNextArg: (inlined: string | null, separated: Array<string>, nextArg: string | undefined) => boolean;
15
+ };
16
+ /**
17
+ * Result of parsing an option, including its inlined value and any following separated values.
18
+ */
19
+ type ReaderOptionValue = {
20
+ inlined: string | null;
21
+ separated: Array<string>;
22
+ };
23
+ /**
24
+ * Option registration/query interface. Subset of {@link ReaderArgs}.
13
25
  */
14
26
  type ReaderOptions = {
15
27
  /**
16
- * Registers an option so the parser can recognise it.
28
+ * Registers an option; all `longs` and `shorts` share the same key.
17
29
  *
18
30
  * @param definition.longs - Long-form names (without `--`).
19
31
  * @param definition.shorts - Short-form names (without `-`).
20
- * @param definition.valued - `true` if the option takes a value; `false` for flags.
32
+ * @param definition.parsing - Parsing behaviour.
21
33
  * @returns A {@link ReaderOptionKey} for later retrieval.
22
34
  * @throws `Error` if a name is already registered or short names overlap.
23
35
  */
24
36
  registerOption(definition: {
25
37
  longs: Array<string>;
26
38
  shorts: Array<string>;
27
- valued: boolean;
39
+ parsing: ReaderOptionParsing;
28
40
  }): ReaderOptionKey;
29
41
  /**
30
- * Returns all values collected for the option identified by `key`.
31
- *
32
- * @param key - Key from {@link ReaderOptions.registerOption}.
33
- * @returns Raw string values, one per occurrence; empty if never provided.
34
- * @throws `Error` if `key` was not registered.
42
+ * Returns all values collected for `key`.
35
43
  */
36
- getOptionValues(key: ReaderOptionKey): Array<string>;
44
+ getOptionValues(key: ReaderOptionKey): Array<ReaderOptionValue>;
37
45
  };
38
46
  /**
39
- * Positional token consumption interface, implemented by {@link ReaderArgs}.
47
+ * Positional consumption interface. Subset of {@link ReaderArgs}.
40
48
  */
41
49
  type ReaderPositionals = {
42
50
  /**
@@ -64,31 +72,29 @@ declare class ReaderArgs {
64
72
  constructor(args: ReadonlyArray<string>);
65
73
  /**
66
74
  * Registers an option; all `longs` and `shorts` share the same key.
67
- * Short names support stacking (e.g. `-abc`) and inline values (e.g. `-nvalue`),
68
- * but must not be prefixes of one another.
75
+ * Short names must not be prefixes of one another.
69
76
  *
70
77
  * @param definition.longs - Long-form names (without `--`).
71
78
  * @param definition.shorts - Short-form names (without `-`).
72
- * @param definition.valued - `true` if the option takes a value; `false` for flags.
79
+ * @param definition.parsing - Parsing behaviour.
73
80
  * @returns A {@link ReaderOptionKey} for {@link ReaderArgs.getOptionValues}.
74
81
  * @throws `Error` if any name is already registered or short names overlap.
75
82
  */
76
83
  registerOption(definition: {
77
84
  longs: Array<string>;
78
85
  shorts: Array<string>;
79
- valued: boolean;
86
+ parsing: ReaderOptionParsing;
80
87
  }): ReaderOptionKey;
81
88
  /**
82
- * Returns all values collected for the option key.
89
+ * Returns all values collected for `key`.
83
90
  *
84
91
  * @param key - Key from {@link ReaderArgs.registerOption}.
85
- * @returns String values, one per occurrence.
92
+ * @returns One entry per occurrence.
86
93
  * @throws `Error` if `key` was not registered.
87
94
  */
88
- getOptionValues(key: ReaderOptionKey): Array<string>;
95
+ getOptionValues(key: ReaderOptionKey): Array<ReaderOptionValue>;
89
96
  /**
90
- * Returns the next bare positional token.
91
- * Parse intervening options as side-effects.
97
+ * Returns the next positional token; parses intervening options as a side-effect.
92
98
  * All tokens after `--` are treated as positionals.
93
99
  *
94
100
  * @returns The next positional, or `undefined` when exhausted.
@@ -99,21 +105,21 @@ declare class ReaderArgs {
99
105
 
100
106
  /**
101
107
  * Decodes a raw CLI string into a typed value.
102
- * A pair of a human-readable `content` name (e.g. `"Number"`) and a `decoder` function.
108
+ * A pair of a human-readable `content` name and a `decoder` function.
103
109
  *
104
- * Built-in: {@link typeString}, {@link typeBoolean}, {@link typeNumber},
105
- * {@link typeInteger}, {@link typeDate}, {@link typeUrl}.
106
- * Composite: {@link typeOneOf}, {@link typeMapped}, {@link typeTuple}, {@link typeList}.
110
+ * Built-in: {@link type}, {@link typeBoolean}, {@link typeNumber},
111
+ * {@link typeInteger}, {@link typeDatetime}, {@link typeUrl}.
112
+ * Composite: {@link typeChoice}, {@link typeConverted}, {@link typeTuple}, {@link typeList}.
107
113
  *
108
114
  * @typeParam Value - Type produced by the decoder.
109
115
  */
110
116
  type Type<Value> = {
111
117
  /**
112
- * Human-readable name shown in help and error messages (e.g. `"String"`, `"Number"`).
118
+ * Human-readable name shown in help and errors (e.g. `"name"`, `"number"`).
113
119
  */
114
120
  content: string;
115
121
  /**
116
- * Converts a raw CLI string into `Value`.
122
+ * Decodes a raw CLI string into `Value`.
117
123
  *
118
124
  * @param input - Raw string from the command line.
119
125
  * @returns The decoded value.
@@ -122,122 +128,133 @@ type Type<Value> = {
122
128
  decoder(input: string): Value;
123
129
  };
124
130
  /**
125
- * Decodes `"true"` / `"yes"` `true` and `"false"` / `"no"` → `false` (case-insensitive).
126
- * Used internally by {@link optionFlag} for the `--flag=<value>` syntax.
131
+ * Decodes a string to `boolean` (case-insensitive).
132
+ * Used by {@link optionFlag} for `--flag=<value>`.
127
133
  *
128
134
  * @example
129
135
  * ```ts
130
- * typeBoolean.decoder("yes") // → true
131
- * typeBoolean.decoder("false") // → false
132
- * typeBoolean.decoder("1") // throws TypoError
136
+ * typeBoolean("flag").decoder("true") // → true
137
+ * typeBoolean("flag").decoder("yes") // → true
138
+ * typeBoolean("flag").decoder("y") // true
139
+ * typeBoolean("flag").decoder("false") // → false
140
+ * typeBoolean("flag").decoder("no") // → false
141
+ * typeBoolean("flag").decoder("n") // → false
133
142
  * ```
134
143
  */
135
- declare const typeBoolean: Type<boolean>;
144
+ declare function typeBoolean(name?: string): Type<boolean>;
136
145
  /**
137
- * Parses a date/time string via `Date.parse` into a `Date` object.
146
+ * Parses a date/time string via `Date.parse`.
138
147
  * Accepts any format supported by `Date.parse`, including ISO 8601.
139
148
  *
140
149
  * @example
141
150
  * ```ts
142
- * typeDate.decoder("2024-01-15") // → Date object for 2024-01-15
143
- * typeDate.decoder("2024-01-15T13:45:30Z") // → Date object for 2024-01-15 13:45:30 UTC
144
- * typeDate.decoder("not a date") // throws TypoError
151
+ * typeDatetime("my-datetime").decoder("2024-01-15") // → Date object for 2024-01-15
152
+ * typeDatetime("my-datetime").decoder("2024-01-15T13:45:30Z") // → Date object for 2024-01-15 13:45:30 UTC
153
+ * typeDatetime("my-datetime").decoder("not a date") // throws TypoError
145
154
  * ```
146
155
  */
147
- declare const typeDate: Type<Date>;
156
+ declare function typeDatetime(name?: string): Type<Date>;
148
157
  /**
149
- * Parses a string into a `number` via `Number()`.
150
- * Accepts integers, floats, and scientific notation; `NaN` throws a {@link TypoError}.
158
+ * Parses a string to `number` via `Number()`; `NaN` throws {@link TypoError}.
151
159
  *
152
160
  * @example
153
161
  * ```ts
154
- * typeNumber.decoder("3.14") // → 3.14
155
- * typeNumber.decoder("-1") // → -1
156
- * typeNumber.decoder("hello") // throws TypoError
162
+ * typeNumber("my-number").decoder("3.14") // → 3.14
163
+ * typeNumber("my-number").decoder("-1") // → -1
164
+ * typeNumber("my-number").decoder("hello") // throws TypoError
157
165
  * ```
158
166
  */
159
- declare const typeNumber: Type<number>;
167
+ declare function typeNumber(name?: string): Type<number>;
160
168
  /**
161
- * Parses an integer string into a `bigint` via `BigInt()`.
162
- * Floats and non-numeric strings throw a {@link TypoError}.
169
+ * Parses an integer string to `bigint` via `BigInt()`.
170
+ * Floats and non-numeric strings throw {@link TypoError}.
163
171
  *
164
172
  * @example
165
173
  * ```ts
166
- * typeInteger.decoder("42") // → 42n
167
- * typeInteger.decoder("3.14") // throws TypoError
168
- * typeInteger.decoder("abc") // throws TypoError
174
+ * typeInteger("my-integer").decoder("42") // → 42n
175
+ * typeInteger("my-integer").decoder("3.14") // throws TypoError
176
+ * typeInteger("my-integer").decoder("abc") // throws TypoError
169
177
  * ```
170
178
  */
171
- declare const typeInteger: Type<bigint>;
179
+ declare function typeInteger(name?: string): Type<bigint>;
172
180
  /**
173
- * Parses an absolute URL string into a `URL` object.
174
- * Relative or malformed URLs throw a {@link TypoError}.
181
+ * Parses an absolute URL string to a `URL` object.
182
+ * Relative or malformed URLs throw {@link TypoError}.
175
183
  *
176
184
  * @example
177
185
  * ```ts
178
- * typeUrl.decoder("https://example.com") // → URL { href: "https://example.com/", ... }
179
- * typeUrl.decoder("not-a-url") // throws TypoError
186
+ * typeUrl("my-url").decoder("https://example.com") // → URL { href: "https://example.com/", ... }
187
+ * typeUrl("my-url").decoder("not-a-url") // throws TypoError
180
188
  * ```
181
189
  */
182
- declare const typeUrl: Type<URL>;
190
+ declare function typeUrl(name?: string): Type<URL>;
183
191
  /**
184
- * Identity decoder passes the raw string through unchanged.
185
- *
192
+ * A named type that accepts any string as input.
193
+ * @param name - Name shown in help and errors (e.g. `"my-value"`).
186
194
  * @example
187
195
  * ```ts
188
- * typeString.decoder("hello") // → "hello"
189
- * typeString.decoder("") // → ""
196
+ * type("greeting").decoder("hello") // → "hello"
197
+ * type("greeting").decoder("") // → ""
190
198
  * ```
191
199
  */
192
- declare const typeString: Type<string>;
200
+ declare function type(name?: string): Type<string>;
193
201
  /**
194
- * Creates a {@link Type} by chaining `before`'s decoder with an `after` transformation.
202
+ * Chains `before`'s decoder with an `after` transformation.
195
203
  * `before` errors are prefixed with `"from: <content>"` for traceability.
196
204
  *
197
205
  * @typeParam Before - Intermediate type from `before.decoder`.
198
206
  * @typeParam After - Final type from `after.decoder`.
199
207
  *
200
- * @param before - Base decoder for the raw string.
201
- * @param after - Transformation applied to the decoded value.
202
- * @param after.content - Name for the resulting type (shown in errors).
203
- * @param after.decoder - Converts a `Before` value to `After`.
208
+ * @param name - Name shown in help and errors (e.g. `"my-value"`).
209
+ * @param before - Base type to decode the raw string.
210
+ * @param mapper - Transforms `before`'s output to the final value; errors are wrapped with context.
204
211
  * @returns A {@link Type}`<After>`.
205
212
  *
206
213
  * @example
207
214
  * ```ts
208
- * const typePort = typeMapped(typeNumber, {
209
- * content: "Port",
210
- * decoder: (n) => {
211
- * if (n < 1 || n > 65535) throw new Error("Out of range");
212
- * return n;
213
- * },
215
+ * const typePort = typeConverted("port", typeNumber(), (n) => {
216
+ * if (n < 1 || n > 65535) throw new Error("Out of range");
217
+ * return n;
214
218
  * });
215
219
  * // "--port 8080" → 8080
216
220
  * // "--port 99999" → TypoError: --port: <PORT>: Port: Out of range
217
221
  * ```
218
222
  */
219
- declare function typeMapped<Before, After>(before: Type<Before>, after: {
220
- content: string;
221
- decoder: (value: Before) => After;
222
- }): Type<After>;
223
+ declare function typeConverted<Before, After>(name: string, before: Type<Before>, mapper: (value: Before) => After): Type<After>;
224
+ /**
225
+ * Adds a name to a {@link Type} for clearer error messages and help text.
226
+ *
227
+ * @param name - Name to use for the type.
228
+ * @param type - Base type to name.
229
+ * @returns A {@link Type} with the given name.
230
+ */
231
+ declare function typeRenamed<Value>(type: Type<Value>, name: string): Type<Value>;
232
+ /**
233
+ * Creates a {@link Type} for filesystem paths with optional existence checks.
234
+ * @param checks - Optional checks for path existence and type (file/directory).
235
+ * @returns A {@link Type}`<string>` representing the path.
236
+ */
237
+ declare function typePath(name?: string, checks?: {
238
+ checkSyncExistAs?: "file" | "directory" | "anything";
239
+ }): Type<string>;
223
240
  /**
224
- * Creates a {@link Type}`<string>` accepting only a fixed set of string values.
225
- * Out-of-set inputs throw a {@link TypoError} listing up to 5 valid options.
241
+ * Creates a {@link Type}`<string>` that only accepts a fixed set of values.
242
+ * Out-of-set inputs throw {@link TypoError} listing up to 5 valid options.
226
243
  *
227
- * @param content - Name shown in help and errors (e.g. `"Environment"`).
244
+ * @param name - Name shown in help and errors.
228
245
  * @param values - Ordered list of accepted values.
229
246
  * @returns A {@link Type}`<string>`.
230
247
  *
231
248
  * @example
232
249
  * ```ts
233
- * const typeEnv = typeOneOf("Environment", ["dev", "staging", "prod"]);
250
+ * const typeEnv = typeChoice("environment", ["dev", "staging", "prod"]);
234
251
  * typeEnv.decoder("prod") // → "prod"
235
252
  * typeEnv.decoder("unknown") // throws TypoError: Invalid value: "unknown" (expected one of: "dev" | "staging" | "prod")
236
253
  * ```
237
254
  */
238
- declare function typeOneOf<const Value extends string>(content: string, values: Array<Value>): Type<Value>;
255
+ declare function typeChoice<const Value extends string>(name: string, values: Array<Value>, caseSensitive?: boolean): Type<Value>;
239
256
  /**
240
- * Splits a delimited string into a fixed-length typed tuple.
257
+ * Splits a delimited string into a typed tuple.
241
258
  * Each part is decoded by the corresponding element type; wrong count or decode failure throws {@link TypoError}.
242
259
  *
243
260
  * @typeParam Elements - Tuple of decoded value types (inferred from `elementTypes`).
@@ -248,7 +265,7 @@ declare function typeOneOf<const Value extends string>(content: string, values:
248
265
  *
249
266
  * @example
250
267
  * ```ts
251
- * const typePoint = typeTuple([typeNumber, typeNumber]);
268
+ * const typePoint = typeTuple([typeNumber("x"), typeNumber("y")]);
252
269
  * typePoint.decoder("3.14,2.71") // → [3.14, 2.71]
253
270
  * typePoint.decoder("1,2,3") // → [1, 2]
254
271
  * typePoint.decoder("x,2") // throws TypoError: at 0: Number: Unable to parse: "x"
@@ -258,7 +275,7 @@ declare function typeTuple<const Elements extends Array<any>>(elementTypes: {
258
275
  [K in keyof Elements]: Type<Elements[K]>;
259
276
  }, separator?: string): Type<Elements>;
260
277
  /**
261
- * Splits a delimited string into a variable-length typed array.
278
+ * Splits a delimited string into a typed array.
262
279
  * Each part is decoded by `elementType`; failed decodes throw {@link TypoError}.
263
280
  * Note: splitting an empty string yields one empty element — prefer {@link optionRepeatable} for a zero-default.
264
281
  *
@@ -274,282 +291,586 @@ declare function typeTuple<const Elements extends Array<any>>(elementTypes: {
274
291
  * typeNumbers.decoder("1,2,3") // → [1, 2, 3]
275
292
  * typeNumbers.decoder("1,x,3") // throws TypoError: at 1: Number: Unable to parse: "x"
276
293
  *
277
- * const typePaths = typeList(typeString, ":");
294
+ * const typePaths = typeList(typePath(), ":");
278
295
  * typePaths.decoder("/usr/bin:/usr/local/bin") // → ["/usr/bin", "/usr/local/bin"]
279
296
  * ```
280
297
  */
281
298
  declare function typeList<Value>(elementType: Type<Value>, separator?: string): Type<Array<Value>>;
282
299
 
283
300
  /**
284
- * A CLI option (flag or valued) with its parsing and usage-generation logic.
285
- *
286
- * Created with {@link optionFlag}, {@link optionSingleValue}, or
287
- * {@link optionRepeatable} and passed via the `options` map of {@link operation}.
288
- *
289
- * @typeParam Value - Decoded value type.
301
+ * Color names for terminal styling, used by {@link TypoStyle}.
302
+ * `dark*` = standard ANSI (30–37); `bright*` = high-intensity (90–97).
290
303
  */
291
- type Option<Value> = {
304
+ type TypoColor = "darkBlack" | "darkRed" | "darkGreen" | "darkYellow" | "darkBlue" | "darkMagenta" | "darkCyan" | "darkWhite" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
305
+ /**
306
+ * Visual styling applied by a {@link TypoSupport} instance.
307
+ * All fields are optional; ignored entirely in `"none"` mode.
308
+ */
309
+ type TypoStyle = {
292
310
  /**
293
- * Returns metadata used to render the `Options:` section of help.
311
+ * Letter case.
294
312
  */
295
- generateUsage(): OptionUsage;
313
+ case?: "upper" | "lower";
296
314
  /**
297
- * Registers the option on `readerOptions` and returns an {@link OptionDecoder}.
315
+ * Foreground (text) color.
298
316
  */
299
- registerAndMakeDecoder(readerOptions: ReaderArgs): OptionDecoder<Value>;
300
- };
301
- /**
302
- * Produced by {@link Option.registerAndMakeDecoder}.
303
- *
304
- * @typeParam Value - Decoded value type.
305
- */
306
- type OptionDecoder<Value> = {
317
+ fgColor?: TypoColor;
307
318
  /**
308
- * Returns the decoded option value.
309
- *
310
- * @throws {@link TypoError} if decoding failed.
319
+ * Background color.
311
320
  */
312
- getAndDecodeValue(): Value;
313
- };
314
- /**
315
- * Human-readable metadata for a single option, used to render the `Options:` section
316
- * of the help output produced by {@link usageToStyledLines}.
317
- */
318
- type OptionUsage = {
321
+ bgColor?: TypoColor;
319
322
  /**
320
- * Long-form name without `--` (e.g. `"verbose"`).
323
+ * Reduced intensity.
321
324
  */
322
- long: Lowercase<string>;
325
+ dim?: boolean;
323
326
  /**
324
- * Short-form name without `-` (e.g. `"v"`).
327
+ * Bold.
325
328
  */
326
- short: string | undefined;
329
+ bold?: boolean;
327
330
  /**
328
- * Help text in usage.
331
+ * Italic.
329
332
  */
330
- description: string | undefined;
333
+ italic?: boolean;
331
334
  /**
332
- * Short note shown in parentheses.
335
+ * Underline.
333
336
  */
334
- hint: string | undefined;
337
+ underline?: boolean;
335
338
  /**
336
- * Value placeholder in help (e.g. `"<FILE>"`). `undefined` for flags.
339
+ * Strikethrough.
337
340
  */
338
- label: Uppercase<string> | undefined;
341
+ strikethrough?: boolean;
339
342
  };
340
343
  /**
341
- * Creates a boolean flag option (`--verbose`, optionally `--flag=no`).
342
- *
343
- * Parsing: absent → `false`; `--flag` / `--flag=yes` → `true`; `--flag=no` → `false`;
344
- * specified more than once → {@link TypoError}.
345
- *
346
- * @param definition - Flag configuration.
347
- * @param definition.long - Long-form name (without `--`).
348
- * @param definition.short - Short-form name (without `-`).
349
- * @param definition.description - Help text.
350
- * @param definition.hint - Short note shown in parentheses.
351
- * @param definition.aliases - Additional names.
352
- * @param definition.default - Default when absent. Defaults to `() => false`.
353
- * @returns An {@link Option}`<boolean>`.
354
- *
355
- * @example
356
- * ```ts
357
- * const verboseFlag = optionFlag({
358
- * long: "verbose",
359
- * short: "v",
360
- * description: "Enable verbose output",
361
- * });
362
- * ```
344
+ * Section title style. Bold dark-green.
363
345
  */
364
- declare function optionFlag(definition: {
365
- long: Lowercase<string>;
366
- short?: string;
367
- description?: string;
368
- hint?: string;
369
- aliases?: {
370
- longs?: Array<Lowercase<string>>;
371
- shorts?: Array<string>;
372
- };
373
- default?: () => boolean;
374
- }): Option<boolean>;
346
+ declare const typoStyleTitle: TypoStyle;
375
347
  /**
376
- * Creates an option that accepts exactly one value (e.g. `--output dist/`).
377
- *
378
- * Parsing: absent → `default()`; once → decoded with `type`; more than once → {@link TypoError}.
379
- * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.
380
- *
381
- * @typeParam Value - Type produced by the decoder.
382
- *
383
- * @param definition - Option configuration.
384
- * @param definition.long - Long-form name (without `--`).
385
- * @param definition.short - Short-form name (without `-`).
386
- * @param definition.description - Help text.
387
- * @param definition.hint - Short note shown in parentheses.
388
- * @param definition.aliases - Additional names.
389
- * @param definition.label - Value placeholder in help. Defaults to uppercased `type.content`.
390
- * @param definition.type - Decoder for the raw string value.
391
- * @param definition.default - Default when absent. Throw to make the option required.
392
- * @returns An {@link Option}`<Value>`.
393
- *
394
- * @example
395
- * ```ts
396
- * const outputOption = optionSingleValue({
397
- * long: "output",
398
- * short: "o",
399
- * type: typeString,
400
- * label: "PATH",
401
- * description: "Output directory",
402
- * default: () => "dist/",
403
- * });
404
- * ```
348
+ * Logic/type identifier style. Bold dark-magenta.
405
349
  */
406
- declare function optionSingleValue<Value>(definition: {
407
- long: Lowercase<string>;
408
- short?: string;
409
- description?: string;
410
- hint?: string;
411
- aliases?: {
412
- longs?: Array<Lowercase<string>>;
413
- shorts?: Array<string>;
414
- };
415
- label?: Uppercase<string>;
416
- type: Type<Value>;
417
- default: () => Value;
418
- }): Option<Value>;
350
+ declare const typoStyleLogic: TypoStyle;
419
351
  /**
420
- * Creates an option that collects every occurrence into an array (e.g. `--file a.ts --file b.ts`).
421
- *
422
- * Parsing: absent → `[]`; N occurrences → array of N decoded values in order.
423
- * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.
424
- *
425
- * @typeParam Value - Type produced by the decoder for each occurrence.
426
- *
427
- * @param definition - Option configuration.
428
- * @param definition.long - Long-form name (without `--`).
429
- * @param definition.short - Short-form name (without `-`).
430
- * @param definition.description - Help text.
431
- * @param definition.hint - Short note shown in parentheses.
432
- * @param definition.aliases - Additional names.
433
- * @param definition.label - Value placeholder in help. Defaults to uppercased `type.content`.
434
- * @param definition.type - Decoder applied to each raw string value.
435
- * @returns An {@link Option}`<Array<Value>>`.
436
- *
437
- * @example
438
- * ```ts
439
- * const filesOption = optionRepeatable({
440
- * long: "file",
441
- * short: "f",
442
- * type: typeString,
443
- * label: "PATH",
444
- * description: "Input file (may be repeated)",
445
- * });
446
- * // Usage: my-cli --file a.ts --file b.ts → ["a.ts", "b.ts"]
447
- * ```
352
+ * Quoted user-input style. Bold dark-yellow.
448
353
  */
449
- declare function optionRepeatable<Value>(definition: {
450
- long: Lowercase<string>;
451
- short?: string;
452
- description?: string;
453
- hint?: string;
454
- aliases?: {
455
- longs?: Array<Lowercase<string>>;
456
- shorts?: Array<string>;
457
- };
458
- label?: Uppercase<string>;
459
- type: Type<Value>;
460
- }): Option<Array<Value>>;
461
-
354
+ declare const typoStyleQuote: TypoStyle;
462
355
  /**
463
- * A bare (non-option) positional argument with its parsing and usage-generation logic.
464
- *
465
- * Created with {@link positionalRequired}, {@link positionalOptional}, or
466
- * {@link positionalVariadics} and passed via the `positionals` array of
467
- * {@link operation}, consumed in declaration order.
468
- *
469
- * @typeParam Value - Decoded value type.
356
+ * Error label style. Bold dark-red.
470
357
  */
471
- type Positional<Value> = {
358
+ declare const typoStyleFailure: TypoStyle;
359
+ /**
360
+ * Option/command name style. Bold dark-cyan.
361
+ */
362
+ declare const typoStyleConstants: TypoStyle;
363
+ /**
364
+ * Positional/user-input label style. Bold dark-blue.
365
+ */
366
+ declare const typoStyleUserInput: TypoStyle;
367
+ /**
368
+ * Strong text style. Bold.
369
+ */
370
+ declare const typoStyleRegularStrong: TypoStyle;
371
+ /**
372
+ * Subtle text style. Italic and dim.
373
+ */
374
+ declare const typoStyleRegularWeaker: TypoStyle;
375
+ /**
376
+ * Immutable styled string segment. Compose into a {@link TypoText}.
377
+ */
378
+ declare class TypoString {
379
+ #private;
472
380
  /**
473
- * Returns metadata used to render the `Positionals:` section of help.
381
+ * @param value - Raw text content.
382
+ * @param typoStyle - Style to apply when rendering. Defaults to `{}` (no style).
474
383
  */
475
- generateUsage(): PositionalUsage;
384
+ constructor(value: string, typoStyle?: TypoStyle);
476
385
  /**
477
- * Consumes the next positional token from `readerPositionals`.
478
- * Returns a decoder that produces the final value.
386
+ * Returns the text styled by `typoSupport`.
387
+ *
388
+ * @param typoSupport - Rendering mode.
479
389
  */
480
- consumeAndMakeDecoder(readerPositionals: ReaderPositionals): PositionalDecoder<Value>;
481
- };
390
+ computeStyledString(typoSupport: TypoSupport): string;
391
+ /**
392
+ * Returns the raw text.
393
+ */
394
+ getRawString(): string;
395
+ }
482
396
  /**
483
- * Produced by {@link Positional.consumeAndMakeDecoder}.
484
- *
485
- * @typeParam Value - Decoded value type.
397
+ * Mutable sequence of {@link TypoString} segments.
486
398
  */
487
- type PositionalDecoder<Value> = {
399
+ declare class TypoText {
400
+ #private;
488
401
  /**
489
- * Returns the decoded positional value.
402
+ * @param segments - Initial text segments
403
+ */
404
+ constructor(...segments: Array<TypoText | Array<TypoString> | TypoString | string>);
405
+ /**
406
+ * Appends new text segment(s).
490
407
  *
491
- * @throws {@link TypoError} if decoding failed.
408
+ * @param segment - Text segment(s) to append.
492
409
  */
493
- decodeValue(): Value;
494
- };
495
- /**
496
- * Human-readable metadata for a single positional argument, used to render the
497
- * `Positionals:` section of the help output produced by {@link usageToStyledLines}.
498
- */
499
- type PositionalUsage = {
410
+ push(segment: TypoText | Array<TypoString> | TypoString | string): void;
500
411
  /**
501
- * Help text.
412
+ * Renders all segments into a single styled string.
413
+ *
414
+ * @param typoSupport - Rendering mode.
415
+ * @returns Concatenated styled string.
502
416
  */
503
- description: string | undefined;
417
+ computeStyledString(typoSupport: TypoSupport): string;
504
418
  /**
505
- * Short note shown in parentheses.
419
+ * Returns the concatenated raw text.
506
420
  */
507
- hint: string | undefined;
421
+ computeRawString(): string;
508
422
  /**
509
- * Placeholder label shown in the usage line and the `Positionals:` section.
510
- * Required: `<NAME>`, optional: `[NAME]`, variadic: `[NAME]...`.
423
+ * Returns the total raw character count.
511
424
  */
512
- label: Uppercase<string>;
513
- };
425
+ computeRawLength(): number;
426
+ }
514
427
  /**
515
- * Creates a required positional — missing token throws {@link TypoError}.
516
- * Label defaults to uppercased `type.content` in angle brackets (e.g. `<STRING>`).
517
- *
518
- * @typeParam Value - Type produced by the decoder.
519
- *
520
- * @param definition - Positional configuration.
521
- * @param definition.description - Help text.
522
- * @param definition.hint - Short note shown in parentheses.
523
- * @param definition.label - Label without brackets; defaults to uppercased `type.content`.
524
- * @param definition.type - Decoder for the raw token.
525
- * @returns A {@link Positional}`<Value>`.
526
- *
527
- * @example
528
- * ```ts
529
- * const namePositional = positionalRequired({
530
- * type: typeString,
531
- * label: "NAME",
532
- * description: "The name to greet",
533
- * });
534
- * // Parses: my-cli Alice → "Alice"
535
- * ```
428
+ * Column-aligned grid of {@link TypoText} cells.
429
+ * Each column is padded to the widest cell (raw chars); the last column is not padded.
536
430
  */
537
- declare function positionalRequired<Value>(definition: {
538
- description?: string;
539
- hint?: string;
540
- label?: Uppercase<string>;
541
- type: Type<Value>;
542
- }): Positional<Value>;
431
+ declare class TypoGrid {
432
+ #private;
433
+ constructor();
434
+ /**
435
+ * Appends a row. All rows should have the same cell count.
436
+ *
437
+ * @param cells - Ordered {@link TypoText} cells.
438
+ */
439
+ pushRow(cells: Array<TypoText>): void;
440
+ /**
441
+ * Renders as an array of styled, column-padded strings.
442
+ *
443
+ * @param typoSupport - Rendering mode.
444
+ * @returns Array of styled strings.
445
+ */
446
+ computeStyledLines(typoSupport: TypoSupport): Array<string>;
447
+ }
543
448
  /**
544
- * Creates an optional positional absent token falls back to `default()`.
545
- * Label defaults to uppercased `type.content` in square brackets (e.g. `[STRING]`).
546
- *
547
- * @typeParam Value - Type produced by the decoder (or the default).
449
+ * `Error` subclass with a {@link TypoText} styled message for rich terminal output.
450
+ * Chains `TypoError` sources after `": "`.
451
+ */
452
+ declare class TypoError extends Error {
453
+ #private;
454
+ /**
455
+ * @param currentTypoText - Styled message for this error.
456
+ * @param source - Optional cause; `TypoError` chains styled text, `Error` appends `.message`, else `String()`.
457
+ */
458
+ constructor(currentTypoText: TypoText, source?: unknown);
459
+ /**
460
+ * Renders the styled message (without `"Error:"` prefix).
461
+ *
462
+ * @param typoSupport - Rendering mode.
463
+ * @returns Styled error string.
464
+ */
465
+ computeStyledString(typoSupport: TypoSupport): string;
466
+ /**
467
+ * Runs `thrower`; wraps any thrown error as a `TypoError` with `context()` prepended.
468
+ *
469
+ * @typeParam Value - Return type of `thrower`.
470
+ * @param thrower - Function to execute; result passed through on success.
471
+ * @param context - Produces the {@link TypoText} prepended to the caught error.
472
+ * @returns Value from `thrower`.
473
+ * @throws `TypoError` wrapping the original error with context prepended.
474
+ */
475
+ static tryWithContext<Value>(thrower: () => Value, context: () => TypoText): Value;
476
+ }
477
+ /**
478
+ * Controls ANSI terminal styling. Create via the static factory methods.
479
+ */
480
+ declare class TypoSupport {
481
+ #private;
482
+ private constructor();
483
+ /**
484
+ * Plain text — no ANSI codes.
485
+ */
486
+ static none(): TypoSupport;
487
+ /**
488
+ * ANSI escape codes for color terminals.
489
+ */
490
+ static tty(): TypoSupport;
491
+ /**
492
+ * Deterministic textual styling for snapshot tests.
493
+ */
494
+ static mock(): TypoSupport;
495
+ /**
496
+ * Auto-detects styling mode from the process environment on best-effort basis.
497
+ */
498
+ static inferFromEnv(): TypoSupport;
499
+ /**
500
+ * Applies `typoStyle` to `value` according to the current mode.
501
+ *
502
+ * @param value - Raw text.
503
+ * @param typoStyle - Style to apply.
504
+ * @returns Styled string.
505
+ */
506
+ computeStyledString(value: string, typoStyle: TypoStyle): string;
507
+ /**
508
+ * Formats any thrown value as `"Error: <message>"` with {@link typoStyleFailure} on the prefix.
509
+ *
510
+ * @param error - Any thrown value.
511
+ * @returns Styled error string.
512
+ */
513
+ computeStyledErrorMessage(error: unknown): string;
514
+ }
515
+
516
+ /**
517
+ * Usage model. Produced by {@link CommandDecoder.generateUsage}, consumed by {@link usageToStyledLines}.
518
+ */
519
+ type UsageCommand = {
520
+ /**
521
+ * Segments of the usage line
522
+ */
523
+ segments: Array<{
524
+ positional: string;
525
+ } | {
526
+ subcommand: string;
527
+ }>;
528
+ /**
529
+ * Command metadata.
530
+ */
531
+ information: CommandInformation;
532
+ /**
533
+ * Positionals in declaration order.
534
+ */
535
+ positionals: Array<UsagePositional>;
536
+ /**
537
+ * Subcommands, populated when none was selected.
538
+ */
539
+ subcommands: Array<UsageSubcommand>;
540
+ /**
541
+ * Options in registration order.
542
+ */
543
+ options: Array<UsageOption>;
544
+ };
545
+ /**
546
+ * Positional metadata for the `Positionals:` section of help.
547
+ */
548
+ type UsagePositional = {
549
+ /**
550
+ * Help text.
551
+ */
552
+ description?: string | undefined;
553
+ /**
554
+ * Short note shown in parentheses.
555
+ */
556
+ hint?: string | undefined;
557
+ /**
558
+ * Placeholder label shown in the usage line and the `Positionals:` section.
559
+ */
560
+ label: string;
561
+ };
562
+ /**
563
+ * Entry in the `Subcommands:` section.
564
+ */
565
+ type UsageSubcommand = {
566
+ /**
567
+ * Token the user types (e.g. `"deploy"`).
568
+ */
569
+ name: string;
570
+ /**
571
+ * From {@link CommandInformation.description}.
572
+ */
573
+ description?: string | undefined;
574
+ /**
575
+ * From {@link CommandInformation.hint}.
576
+ */
577
+ hint?: string | undefined;
578
+ };
579
+ /**
580
+ * Option metadata for the `Options:` section of help.
581
+ */
582
+ type UsageOption = {
583
+ /**
584
+ * Short-form name without `-` (e.g. `"v"`).
585
+ */
586
+ short?: string | undefined;
587
+ /**
588
+ * Long-form name without `--` (e.g. `"verbose"`).
589
+ */
590
+ long: string;
591
+ /**
592
+ * Value placeholder in help (e.g. `"<FILE>"`).
593
+ */
594
+ label?: string | undefined;
595
+ /**
596
+ * Extra annotation appended to the option label in help.
597
+ */
598
+ annotation?: string | undefined;
599
+ /**
600
+ * Help text.
601
+ */
602
+ description?: string | undefined;
603
+ /**
604
+ * Short note shown in parentheses.
605
+ */
606
+ hint?: string | undefined;
607
+ };
608
+ /**
609
+ * Converts a {@link UsageCommand} model into an array of styled lines ready to be
610
+ * joined with `"\n"` and printed to the terminal.
611
+ *
612
+ * The output format is:
613
+ * ```
614
+ * Usage: <cliName> [segments...]
615
+ *
616
+ * <description> (<hint>)
617
+ * <detail lines...>
618
+ *
619
+ * Positionals:
620
+ * <LABEL> <description> (<hint>)
621
+ *
622
+ * Subcommands:
623
+ * <name> <description> (<hint>)
624
+ *
625
+ * Options:
626
+ * -s, --long <LABEL><annotation> <description> (<hint>)
627
+ *
628
+ * Examples:
629
+ * <description>
630
+ * <command line>
631
+ *
632
+ * ```
633
+ * Sections that have no entries are omitted. The trailing empty line is always included.
634
+ *
635
+ * Column alignment per section via {@link TypoGrid}.
636
+ *
637
+ * @param params.cliName - Program name for the usage line.
638
+ * @param params.usage - From {@link CommandDecoder.generateUsage}.
639
+ * @param params.typoSupport - Rendering mode.
640
+ * @returns Styled lines; includes a trailing empty string.
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * const lines = usageToStyledLines({
645
+ * cliName: "my-cli",
646
+ * usage: commandDecoder.generateUsage(),
647
+ * typoSupport: TypoSupport.tty(),
648
+ * });
649
+ * process.stdout.write(lines.join("\n"));
650
+ * ```
651
+ */
652
+ declare function usageToStyledLines(params: {
653
+ cliName: string;
654
+ usage: UsageCommand;
655
+ typoSupport: TypoSupport;
656
+ }): string[];
657
+
658
+ /**
659
+ * A CLI option. Created with {@link optionFlag}, {@link optionSingleValue},
660
+ * or {@link optionRepeatable}.
661
+ *
662
+ * @typeParam Value - Decoded value type.
663
+ */
664
+ type Option<Value> = {
665
+ /**
666
+ * Returns metadata for the `Options:` section.
667
+ */
668
+ generateUsage(): UsageOption;
669
+ /**
670
+ * Registers the option on `readerOptions` and returns an {@link OptionDecoder}.
671
+ */
672
+ registerAndMakeDecoder(readerOptions: ReaderArgs): OptionDecoder<Value>;
673
+ };
674
+ /**
675
+ * Produced by {@link Option.registerAndMakeDecoder}.
676
+ *
677
+ * @typeParam Value - Decoded value type.
678
+ */
679
+ type OptionDecoder<Value> = {
680
+ /**
681
+ * Returns the decoded option value.
682
+ *
683
+ * @throws {@link TypoError} if decoding failed.
684
+ */
685
+ getAndDecodeValue(): Value;
686
+ };
687
+ /**
688
+ * Creates a boolean flag option (`--verbose`, optionally `--flag=no`).
689
+ *
690
+ * Parsing: absent → default value; `--flag` / `--flag=yes` → `true`; `--flag=no` → `false`;
691
+ * specified more than once → throws {@link TypoError}.
692
+ *
693
+ * @param definition.long - Long-form name (without `--`).
694
+ * @param definition.short - Short-form name (without `-`).
695
+ * @param definition.description - Help text.
696
+ * @param definition.hint - Short note shown in parentheses.
697
+ * @param definition.aliases - Additional names.
698
+ * @param definition.default - Default value when absent.
699
+ * @returns An {@link Option}`<boolean>`.
700
+ *
701
+ * @example
702
+ * ```ts
703
+ * const verboseFlag = optionFlag({
704
+ * long: "verbose",
705
+ * short: "v",
706
+ * description: "Enable verbose output",
707
+ * });
708
+ * // Usage:
709
+ * // my-cli → false
710
+ * // my-cli --verbose → true
711
+ * // my-cli --verbose=yes → true
712
+ * // my-cli -v=no → false
713
+ * ```
714
+ */
715
+ declare function optionFlag(definition: {
716
+ long: string;
717
+ short?: string;
718
+ description?: string;
719
+ hint?: string;
720
+ aliases?: {
721
+ longs?: Array<string>;
722
+ shorts?: Array<string>;
723
+ };
724
+ default?: boolean;
725
+ }): Option<boolean>;
726
+ /**
727
+ * Creates an option that accepts exactly one value (e.g. `--output dist/`).
728
+ *
729
+ * Parsing: absent → `defaultValue()`; once → decoded with `type`; more than once → {@link TypoError}.
730
+ * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.
731
+ *
732
+ * @typeParam Value - Type produced by the decoder.
733
+ *
734
+ * @param definition.long - Long-form name (without `--`).
735
+ * @param definition.short - Short-form name (without `-`).
736
+ * @param definition.description - Help text.
737
+ * @param definition.hint - Short note shown in parentheses.
738
+ * @param definition.aliases - Additional names.
739
+ * @param definition.type - Decoder for the raw string value.
740
+ * @param definition.valueWhenNotDefined - Default value when the option is not specified at all.
741
+ * @param definition.valueWhenNotInlined - Default value when the option is specified without an inline value (e.g. `--option` or `-o`).
742
+ * @returns An {@link Option}`<Value>`.
743
+ *
744
+ * @example
745
+ * ```ts
746
+ * const outputOption = optionSingleValue({
747
+ * long: "output",
748
+ * short: "o",
749
+ * type: typePath(),
750
+ * description: "Output directory",
751
+ * valueWhenNotDefined: () => "dist",
752
+ * });
753
+ * // Usage:
754
+ * // my-cli → "dist"
755
+ * // my-cli --output folder → "folder"
756
+ * // my-cli -o folder → "folder"
757
+ * ```
758
+ */
759
+ declare function optionSingleValue<Value>(definition: {
760
+ long: string;
761
+ short?: string;
762
+ description?: string;
763
+ hint?: string;
764
+ aliases?: {
765
+ longs?: Array<string>;
766
+ shorts?: Array<string>;
767
+ };
768
+ type: Type<Value>;
769
+ defaultWhenNotDefined: () => Value;
770
+ defaultWhenNotInlined?: () => Value;
771
+ }): Option<Value>;
772
+ /**
773
+ * Creates an option that collects every occurrence into an array (e.g. `--file a.ts --file b.ts`).
774
+ *
775
+ * Parsing: absent → `[]`; N occurrences → array of N decoded values in order.
776
+ * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.
777
+ *
778
+ * @typeParam Value - Type produced by the decoder for each occurrence.
779
+ *
780
+ * @param definition.long - Long-form name (without `--`).
781
+ * @param definition.short - Short-form name (without `-`).
782
+ * @param definition.description - Help text.
783
+ * @param definition.hint - Short note shown in parentheses.
784
+ * @param definition.aliases - Additional names.
785
+ * @param definition.type - Decoder applied to each raw string value.
786
+ * @returns An {@link Option}`<Array<Value>>`.
787
+ *
788
+ * @example
789
+ * ```ts
790
+ * const filesOption = optionRepeatable({
791
+ * long: "file",
792
+ * short: "f",
793
+ * type: typeString,
794
+ * label: "PATH",
795
+ * description: "Input file (may be repeated)",
796
+ * });
797
+ * // Usage: my-cli --file a.ts --file b.ts → ["a.ts", "b.ts"]
798
+ * ```
799
+ */
800
+ declare function optionRepeatable<Value>(definition: {
801
+ long: string;
802
+ short?: string;
803
+ description?: string;
804
+ hint?: string;
805
+ aliases?: {
806
+ longs?: Array<string>;
807
+ shorts?: Array<string>;
808
+ };
809
+ type: Type<Value>;
810
+ }): Option<Array<Value>>;
811
+
812
+ /**
813
+ * A positional argument. Created with {@link positionalRequired}, {@link positionalOptional},
814
+ * or {@link positionalVariadics}.
815
+ *
816
+ * @typeParam Value - Decoded value type.
817
+ */
818
+ type Positional<Value> = {
819
+ /**
820
+ * Returns metadata for the `Positionals:` section.
821
+ */
822
+ generateUsage(): UsagePositional;
823
+ /**
824
+ * Consumes the next positional token from `readerPositionals`.
825
+ * Returns a decoder that produces the final value.
826
+ */
827
+ consumeAndMakeDecoder(readerPositionals: ReaderPositionals): PositionalDecoder<Value>;
828
+ };
829
+ /**
830
+ * Produced by {@link Positional.consumeAndMakeDecoder}.
831
+ *
832
+ * @typeParam Value - Decoded value type.
833
+ */
834
+ type PositionalDecoder<Value> = {
835
+ /**
836
+ * Returns the decoded positional value.
837
+ *
838
+ * @throws {@link TypoError} if decoding failed.
839
+ */
840
+ decodeValue(): Value;
841
+ };
842
+ /**
843
+ * Creates a required positional — missing token throws {@link TypoError}.
844
+ *
845
+ * @typeParam Value - Type produced by the decoder.
846
+ *
847
+ * @param definition.description - Help text.
848
+ * @param definition.hint - Short note shown in parentheses.
849
+ * @param definition.type - Decoder for the raw token.
850
+ * @returns A {@link Positional}`<Value>`.
851
+ *
852
+ * @example
853
+ * ```ts
854
+ * const namePositional = positionalRequired({
855
+ * type: type("name"),
856
+ * description: "The name to greet",
857
+ * });
858
+ * // Usage:
859
+ * // my-cli Alice → "Alice"
860
+ * ```
861
+ */
862
+ declare function positionalRequired<Value>(definition: {
863
+ description?: string;
864
+ hint?: string;
865
+ type: Type<Value>;
866
+ }): Positional<Value>;
867
+ /**
868
+ * Creates an optional positional — absent token falls back to `default()`.
869
+ *
870
+ * @typeParam Value - Type produced by the decoder (or the default).
548
871
  *
549
- * @param definition - Positional configuration.
550
872
  * @param definition.description - Help text.
551
873
  * @param definition.hint - Short note shown in parentheses.
552
- * @param definition.label - Label without brackets; defaults to uppercased `type.content`.
553
874
  * @param definition.type - Decoder for the raw token.
554
875
  * @param definition.default - Value when absent. Throw to make it required.
555
876
  * @returns A {@link Positional}`<Value>`.
@@ -557,52 +878,48 @@ declare function positionalRequired<Value>(definition: {
557
878
  * @example
558
879
  * ```ts
559
880
  * const greeteePositional = positionalOptional({
560
- * type: typeString,
561
- * label: "NAME",
881
+ * type: type("name"),
562
882
  * description: "Name to greet (default: world)",
563
883
  * default: () => "world",
564
884
  * });
565
- * // my-cli → "world"
566
- * // my-cli Alice → "Alice"
885
+ * // Usage:
886
+ * // my-cli → "world"
887
+ * // my-cli Alice → "Alice"
567
888
  * ```
568
889
  */
569
890
  declare function positionalOptional<Value>(definition: {
570
891
  description?: string;
571
892
  hint?: string;
572
- label?: Uppercase<string>;
573
893
  type: Type<Value>;
574
894
  default: () => Value;
575
895
  }): Positional<Value>;
576
896
  /**
577
897
  * Creates a variadic positional that collects zero or more remaining tokens into an array.
578
- * Stops at `endDelimiter` (consumed, not included). Label: `[TYPE]...` notation.
898
+ * Optionally stops at `endDelimiter` (consumed, not included).
579
899
  *
580
900
  * @typeParam Value - Type produced by the decoder for each token.
581
901
  *
582
- * @param definition - Positional configuration.
583
902
  * @param definition.endDelimiter - Sentinel token that stops collection (consumed, not included).
584
903
  * @param definition.description - Help text.
585
904
  * @param definition.hint - Short note shown in parentheses.
586
- * @param definition.label - Label without brackets; defaults to uppercased `type.content`.
587
905
  * @param definition.type - Decoder applied to each token.
588
906
  * @returns A {@link Positional}`<Array<Value>>`.
589
907
  *
590
908
  * @example
591
909
  * ```ts
592
910
  * const filesPositional = positionalVariadics({
593
- * type: typeString,
594
- * label: "FILE",
911
+ * type: typePath(),
595
912
  * description: "Files to process",
596
913
  * });
597
- * // my-cli a.ts b.ts c.ts → ["a.ts", "b.ts", "c.ts"]
598
- * // my-cli → []
914
+ * // Usage:
915
+ * // my-cli → []
916
+ * // my-cli a.ts b.ts c.ts → ["a.ts", "b.ts", "c.ts"]
599
917
  * ```
600
918
  */
601
919
  declare function positionalVariadics<Value>(definition: {
602
920
  endDelimiter?: string;
603
921
  description?: string;
604
922
  hint?: string;
605
- label?: Uppercase<string>;
606
923
  type: Type<Value>;
607
924
  }): Positional<Array<Value>>;
608
925
 
@@ -612,14 +929,23 @@ declare function positionalVariadics<Value>(definition: {
612
929
  * Created with {@link operation} and passed to {@link command},
613
930
  * {@link commandWithSubcommands}, or {@link commandChained}.
614
931
  *
615
- * @typeParam Context - Injected at execution time; forwarded to handlers. Use to inject dependencies.
616
- * @typeParam Result - Value produced on execution; typically `void` for leaf commands.
932
+ * @typeParam Context - Injected at execution; forwarded to handlers.
933
+ * @typeParam Result - Value produced on execution; typically `void`.
617
934
  */
618
935
  type Operation<Context, Result> = {
619
936
  /**
620
937
  * Returns usage metadata without consuming any arguments.
621
938
  */
622
- generateUsage(): OperationUsage;
939
+ generateUsage(): {
940
+ /**
941
+ * Registered options.
942
+ */
943
+ options: Array<UsageOption>;
944
+ /**
945
+ * Declared positionals, in order.
946
+ */
947
+ positionals: Array<UsagePositional>;
948
+ };
623
949
  /**
624
950
  * Consumes args from `readerArgs` and returns an {@link OperationDecoder}.
625
951
  */
@@ -651,26 +977,10 @@ type OperationInterpreter<Context, Result> = {
651
977
  */
652
978
  executeWithContext(context: Context): Promise<Result>;
653
979
  };
654
- /**
655
- * Usage metadata produced by {@link Operation.generateUsage}.
656
- * Consumed when building {@link CommandUsage}.
657
- */
658
- type OperationUsage = {
659
- /**
660
- * Usage descriptors for all registered options.
661
- */
662
- options: Array<OptionUsage>;
663
- /**
664
- * Usage descriptors for all declared positionals, in order.
665
- */
666
- positionals: Array<PositionalUsage>;
667
- };
668
980
  /**
669
981
  * Creates an {@link Operation} from options, positionals, and an async handler.
670
982
  *
671
- * The `handler` receives the parent `context` and an `inputs` object with
672
- * `options` (keyed by the same names declared in `inputs.options`) and
673
- * `positionals` (a tuple in declaration order).
983
+ * The `handler` receives `context` and `inputs` with decoded `options` and `positionals`.
674
984
  *
675
985
  * @typeParam Context - Context type accepted by the handler.
676
986
  * @typeParam Result - Return type of the handler.
@@ -681,20 +991,20 @@ type OperationUsage = {
681
991
  * @param inputs.options - Map of keys to {@link Option} descriptors.
682
992
  * @param inputs.positionals - Ordered array of {@link Positional} descriptors.
683
993
  * @param handler - Async function implementing the command logic.
684
- * @returns An {@link Operation} ready to be composed into a command.
994
+ * @returns An {@link Operation}.
685
995
  *
686
996
  * @example
687
997
  * ```ts
688
998
  * const greetOperation = operation(
689
999
  * {
690
1000
  * options: {
691
- * loud: optionFlag({ long: "loud", description: "Print in uppercase" }),
1001
+ * loud: optionFlag({ long: "loud", description: "Print in uppercase", default: false }),
692
1002
  * },
693
1003
  * positionals: [
694
- * positionalRequired({ type: typeString, label: "NAME", description: "Name to greet" }),
1004
+ * positionalRequired({ type: type("name"), description: "Name to greet" }),
695
1005
  * ],
696
1006
  * },
697
- * async (_ctx, { options: { loud }, positionals: [name] }) => {
1007
+ * async function (_ctx, { options: { loud }, positionals: [name] }) {
698
1008
  * const message = `Hello, ${name}!`;
699
1009
  * console.log(loud ? message.toUpperCase() : message);
700
1010
  * },
@@ -716,20 +1026,18 @@ declare function operation<Context, Result, Options extends {
716
1026
  }) => Promise<Result>): Operation<Context, Result>;
717
1027
 
718
1028
  /**
719
- * A CLI command parses arguments and executes within a given context.
720
- * Created with {@link command}, {@link commandWithSubcommands}, or {@link commandChained}.
721
- * Usually passed through {@link runAndExit} to run.
1029
+ * A CLI command. Created with {@link command}, {@link commandWithSubcommands}, or {@link commandChained}.
722
1030
  *
723
- * @typeParam Context - Injected at execution time; forwarded to handlers. Use to inject dependencies.
724
- * @typeParam Result - Value produced on execution; typically `void` for leaf commands.
1031
+ * @typeParam Context - Injected at execution; forwarded to handlers.
1032
+ * @typeParam Result - Produced on execution; typically `void`.
725
1033
  */
726
1034
  type Command<Context, Result> = {
727
1035
  /**
728
- * Returns the command's static metadata.
1036
+ * Returns static metadata.
729
1037
  */
730
1038
  getInformation(): CommandInformation;
731
1039
  /**
732
- * Consumes args in a `readerArgs` and returns a {@link CommandDecoder}.
1040
+ * Registers options/positionals on `readerArgs`; returns a {@link CommandDecoder}.
733
1041
  */
734
1042
  consumeAndMakeDecoder(readerArgs: ReaderArgs): CommandDecoder<Context, Result>;
735
1043
  };
@@ -741,10 +1049,9 @@ type Command<Context, Result> = {
741
1049
  */
742
1050
  type CommandDecoder<Context, Result> = {
743
1051
  /**
744
- * Builds the {@link CommandUsage} for the current command path.
745
- * Used for `--help` and `usageOnError`.
1052
+ * Returns {@link UsageCommand} for the current command path.
746
1053
  */
747
- generateUsage(): CommandUsage;
1054
+ generateUsage(): UsageCommand;
748
1055
  /**
749
1056
  * Creates a ready-to-execute {@link CommandInterpreter}.
750
1057
  *
@@ -755,7 +1062,7 @@ type CommandDecoder<Context, Result> = {
755
1062
  /**
756
1063
  * A fully parsed, decoded and ready-to-execute command.
757
1064
  *
758
- * @typeParam Context - Caller-supplied context.
1065
+ * @typeParam Context - Context passed to the handler.
759
1066
  * @typeParam Result - Value produced on success.
760
1067
  */
761
1068
  type CommandInterpreter<Context, Result> = {
@@ -765,15 +1072,15 @@ type CommandInterpreter<Context, Result> = {
765
1072
  executeWithContext(context: Context): Promise<Result>;
766
1073
  };
767
1074
  /**
768
- * Static metadata for a command, shown in `--help` output via {@link usageToStyledLines}.
1075
+ * Command metadata shown in `--help` output.
769
1076
  */
770
1077
  type CommandInformation = {
771
1078
  /**
772
- * Short description shown in the usage header.
1079
+ * Shown in the usage header.
773
1080
  */
774
1081
  description: string;
775
1082
  /**
776
- * Short note shown in parentheses (e.g. `"deprecated"`, `"experimental"`).
1083
+ * Shown in parentheses, e.g. `"deprecated"`, `"experimental"`.
777
1084
  */
778
1085
  hint?: string;
779
1086
  /**
@@ -781,7 +1088,7 @@ type CommandInformation = {
781
1088
  */
782
1089
  details?: Array<string>;
783
1090
  /**
784
- * Examples shown in the `Examples:` section of the usage output.
1091
+ * Shown in the `Examples:` section.
785
1092
  */
786
1093
  examples?: Array<{
787
1094
  /**
@@ -789,7 +1096,7 @@ type CommandInformation = {
789
1096
  */
790
1097
  explanation: string;
791
1098
  /**
792
- * Command line args to show as an example of usage.
1099
+ * Example command args.
793
1100
  */
794
1101
  commandArgs: Array<string | {
795
1102
  positional: string;
@@ -798,75 +1105,24 @@ type CommandInformation = {
798
1105
  } | {
799
1106
  option: {
800
1107
  long: string;
801
- value?: string;
1108
+ inlined?: string;
1109
+ separated?: Array<string>;
802
1110
  } | {
803
1111
  short: string;
804
- value?: string;
1112
+ inlined?: string;
1113
+ separated?: Array<string>;
805
1114
  };
806
1115
  }>;
807
1116
  }>;
808
1117
  };
809
- /**
810
- * Full usage/help model.
811
- * Produced by {@link CommandDecoder.generateUsage},
812
- * Consumed by {@link usageToStyledLines}.
813
- */
814
- type CommandUsage = {
815
- /**
816
- * Segments forming the usage line
817
- * (e.g. `my-cli <POSITIONAL> subcommand <ANOTHER_POSITIONAL>`).
818
- */
819
- segments: Array<CommandUsageSegment>;
820
- /**
821
- * Command's static metadata.
822
- */
823
- information: CommandInformation;
824
- /**
825
- * Positionals in declaration order.
826
- */
827
- positionals: Array<PositionalUsage>;
828
- /**
829
- * Available subcommands. Non-empty when subcommand was not specified.
830
- */
831
- subcommands: Array<CommandUsageSubcommand>;
832
- /**
833
- * Options in registration order.
834
- */
835
- options: Array<OptionUsage>;
836
- };
837
- /**
838
- * One element in the usage segment trail.
839
- */
840
- type CommandUsageSegment = {
841
- positional: string;
842
- } | {
843
- command: string;
844
- };
845
- /**
846
- * Subcommand entry shown in the `Subcommands:` section of the usage output.
847
- */
848
- type CommandUsageSubcommand = {
849
- /**
850
- * Literal token the user types (e.g. `"deploy"`).
851
- */
852
- name: string;
853
- /**
854
- * Short description from the subcommand's {@link CommandInformation}.
855
- */
856
- description: string | undefined;
857
- /**
858
- * Hint from the subcommand's {@link CommandInformation}.
859
- */
860
- hint: string | undefined;
861
- };
862
1118
  /**
863
1119
  * Creates a leaf command that directly executes an {@link Operation}.
864
1120
  *
865
1121
  * @typeParam Context - Context forwarded to the handler.
866
1122
  * @typeParam Result - Value returned by the handler.
867
1123
  *
868
- * @param information - Command metadata (description, hint, details).
869
- * @param operation - Defines: options, positionals, and the handler.
1124
+ * @param information - Command metadata.
1125
+ * @param operation - Options, positionals, and handler.
870
1126
  * @returns A {@link Command}.
871
1127
  *
872
1128
  * @example
@@ -874,7 +1130,7 @@ type CommandUsageSubcommand = {
874
1130
  * const greet = command(
875
1131
  * { description: "Greet a user" },
876
1132
  * operation(
877
- * { options: {}, positionals: [positionalRequired({ type: typeString, label: "NAME" })] },
1133
+ * { options: {}, positionals: [positionalRequired({ type: type("name") })] },
878
1134
  * async (_ctx, { positionals: [name] }) => console.log(`Hello, ${name}!`),
879
1135
  * ),
880
1136
  * );
@@ -882,17 +1138,16 @@ type CommandUsageSubcommand = {
882
1138
  */
883
1139
  declare function command<Context, Result>(information: CommandInformation, operation: Operation<Context, Result>): Command<Context, Result>;
884
1140
  /**
885
- * Creates a command that runs an {@link Operation} to produce a `Payload`,
886
- * then dispatches to a named subcommand based on the next positional token.
1141
+ * Creates a command that runs `operation` first, then dispatches to a named subcommand.
887
1142
  *
888
1143
  * @typeParam Context - Context accepted by `operation`.
889
1144
  * @typeParam Payload - Output of `operation`; becomes the subcommand's context.
890
1145
  * @typeParam Result - Value produced by the selected subcommand.
891
1146
  *
892
- * @param information - Command metadata (description, hint, details).
893
- * @param operation - Always runs first; its output becomes the subcommand's context.
1147
+ * @param information - Command metadata.
1148
+ * @param operation - Runs first; output becomes the subcommand's context.
894
1149
  * @param subcommands - Map of subcommand names to their {@link Command}s.
895
- * @returns A {@link Command} that dispatches to one of the provided subcommands.
1150
+ * @returns A dispatching {@link Command}.
896
1151
  *
897
1152
  * @example
898
1153
  * ```ts
@@ -907,7 +1162,7 @@ declare function command<Context, Result>(information: CommandInformation, opera
907
1162
  * ```
908
1163
  */
909
1164
  declare function commandWithSubcommands<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, subcommands: {
910
- [subcommand: Lowercase<string>]: Command<Payload, Result>;
1165
+ [subcommand: string]: Command<Payload, Result>;
911
1166
  }): Command<Context, Result>;
912
1167
  /**
913
1168
  * Chains an {@link Operation} and a {@link Command}: `operation` runs first, its
@@ -917,22 +1172,10 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
917
1172
  * @typeParam Payload - Output of `operation`; becomes `subcommand`'s context.
918
1173
  * @typeParam Result - Value produced by `subcommand`.
919
1174
  *
920
- * @param information - Command metadata (description, hint, details).
921
- * @param operation - First stage; its output is passed as `subcommand`'s context.
922
- * @param subcommand - Second stage, executed after `operation`.
923
- * @returns A {@link Command} transparently composing the two stages.
924
- *
925
- * @example
926
- * ```ts
927
- * const authenticatedDeploy = commandChained(
928
- * { description: "Authenticate then deploy" },
929
- * operation(
930
- * { options: { token: optionSingleValue({ long: "token", type: typeString, default: () => "" }) }, positionals: [] },
931
- * async (_ctx, { options: { token } }) => ({ token }),
932
- * ),
933
- * command({ description: "Deploy" }, deployOperation),
934
- * );
935
- * ```
1175
+ * @param information - Command metadata.
1176
+ * @param operation - Runs first; output becomes `subcommand`'s context.
1177
+ * @param subcommand - Runs after `operation`.
1178
+ * @returns A {@link Command} composing both stages.
936
1179
  */
937
1180
  declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, subcommand: Command<Payload, Result>): Command<Context, Result>;
938
1181
 
@@ -940,17 +1183,17 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
940
1183
  * Main entry point: parses CLI arguments, executes the matched command, and exits.
941
1184
  * Handles `--help`, `--version`, usage-on-error, and exit codes.
942
1185
  *
943
- * Exit codes: `0` on success / `--help` / `--version`; `1` on parse or execution error.
1186
+ * Exit codes:
1187
+ * - `0` on success / `--help` / `--version`
1188
+ * - `1` on parse error or execution error.
944
1189
  *
945
- * @typeParam Context - Passed unchanged to the command handler; use to inject dependencies.
1190
+ * @typeParam Context - Forwarded unchanged to the handler.
946
1191
  *
947
1192
  * @param cliName - Program name used in usage and `--version` output.
948
1193
  * @param cliArgs - Raw arguments, typically `process.argv.slice(2)`.
949
- * @param context - Forwarded to the command handler, injected dependencies.
1194
+ * @param context - Forwarded to the handler.
950
1195
  * @param command - Root {@link Command}.
951
- * @param options - Optional runner configuration.
952
- * @param options.useTtyColors - Color mode: `true` (always), `false` (never),
953
- * `"mock"` (snapshot-friendly), `undefined` (auto-detect from env).
1196
+ * @param options.colorSetup - Configures color support; enables `--color` flag if set to `"flag"`.
954
1197
  * @param options.usageOnHelp - Enables `--help` flag (default `true`).
955
1198
  * @param options.usageOnError - Prints usage to stderr on parse error (default `true`).
956
1199
  * @param options.buildVersion - Enables `--version`; prints `<cliName> <buildVersion>`.
@@ -961,13 +1204,13 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
961
1204
  *
962
1205
  * @example
963
1206
  * ```ts
964
- * import { runAndExit, command, operation, positionalRequired, typeString } from "cli-kiss";
1207
+ * import { runAndExit, command, operation, positionalRequired, type } from "cli-kiss";
965
1208
  *
966
1209
  * const greetCommand = command(
967
1210
  * { description: "Greet someone" },
968
1211
  * operation(
969
- * { options: {}, positionals: [positionalRequired({ type: typeString, label: "NAME" })] },
970
- * async (_ctx, { positionals: [name] }) => {
1212
+ * { options: {}, positionals: [positionalRequired({ type: type("name") })] },
1213
+ * async function (_ctx, { positionals: [name] }) {
971
1214
  * console.log(`Hello, ${name}!`);
972
1215
  * },
973
1216
  * ),
@@ -978,8 +1221,8 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
978
1221
  * });
979
1222
  * ```
980
1223
  */
981
- declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: ReadonlyArray<string>, context: Context, command: Command<Context, void>, options?: {
982
- useTtyColors?: boolean | undefined | "mock";
1224
+ declare function runAndExit<Context>(cliName: string, cliArgs: ReadonlyArray<string>, context: Context, command: Command<Context, void>, options?: {
1225
+ colorSetup?: "flag" | "env" | "always" | "never" | "mock" | undefined;
983
1226
  usageOnHelp?: boolean | undefined;
984
1227
  usageOnError?: boolean | undefined;
985
1228
  buildVersion?: string | undefined;
@@ -987,285 +1230,4 @@ declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: Readon
987
1230
  onExit?: ((code: number) => never) | undefined;
988
1231
  }): Promise<never>;
989
1232
 
990
- /**
991
- * Color names for terminal styling, used by {@link TypoStyle}.
992
- * `dark*` = standard ANSI (30–37); `bright*` = high-intensity (90–97).
993
- */
994
- type TypoColor = "darkBlack" | "darkRed" | "darkGreen" | "darkYellow" | "darkBlue" | "darkMagenta" | "darkCyan" | "darkWhite" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
995
- /**
996
- * Visual styling applied by a {@link TypoSupport} instance.
997
- * All fields are optional; ignored entirely in `"none"` mode.
998
- */
999
- type TypoStyle = {
1000
- /**
1001
- * Foreground (text) color.
1002
- */
1003
- fgColor?: TypoColor;
1004
- /**
1005
- * Background color.
1006
- */
1007
- bgColor?: TypoColor;
1008
- /**
1009
- * Render with reduced intensity.
1010
- */
1011
- dim?: boolean;
1012
- /**
1013
- * Render in bold.
1014
- */
1015
- bold?: boolean;
1016
- /**
1017
- * Render in italic.
1018
- */
1019
- italic?: boolean;
1020
- /**
1021
- * Render with an underline.
1022
- */
1023
- underline?: boolean;
1024
- /**
1025
- * Render with a strikethrough.
1026
- */
1027
- strikethrough?: boolean;
1028
- };
1029
- /**
1030
- * Pre-defined style for section titles (e.g. `"Positionals:"`). Bold dark-green.
1031
- */
1032
- declare const typoStyleTitle: TypoStyle;
1033
- /**
1034
- * Pre-defined style for logic/type identifiers in error messages. Bold dark-magenta.
1035
- */
1036
- declare const typoStyleLogic: TypoStyle;
1037
- /**
1038
- * Pre-defined style for quoted user-supplied values in error messages. Bold dark-yellow.
1039
- */
1040
- declare const typoStyleQuote: TypoStyle;
1041
- /**
1042
- * Pre-defined style for failure/error labels (e.g. `"Error:"`). Bold dark-red.
1043
- */
1044
- declare const typoStyleFailure: TypoStyle;
1045
- /**
1046
- * Pre-defined style for CLI flag/option/command names. Bold dark-cyan.
1047
- */
1048
- declare const typoStyleConstants: TypoStyle;
1049
- /**
1050
- * Pre-defined style for positional placeholders and user-input labels. Bold dark-blue.
1051
- */
1052
- declare const typoStyleUserInput: TypoStyle;
1053
- /**
1054
- * Pre-defined style for strong regular text (e.g. command descriptions). Bold.
1055
- */
1056
- declare const typoStyleRegularStrong: TypoStyle;
1057
- /**
1058
- * Pre-defined style for subtle supplementary text (e.g. hints). Italic and dim.
1059
- */
1060
- declare const typoStyleRegularWeaker: TypoStyle;
1061
- /**
1062
- * An immutable styled string segment: a raw text value paired with a {@link TypoStyle}.
1063
- * Compose multiple segments into a {@link TypoText}; rendering is deferred to {@link TypoString.computeStyledString}.
1064
- */
1065
- declare class TypoString {
1066
- #private;
1067
- /**
1068
- * @param value - Raw text content.
1069
- * @param typoStyle - Style to apply when rendering. Defaults to `{}` (no style).
1070
- */
1071
- constructor(value: string, typoStyle?: TypoStyle);
1072
- /**
1073
- * Returns the unstyled raw text content.
1074
- */
1075
- getRawString(): string;
1076
- /**
1077
- * Returns the text styled by `typoSupport`.
1078
- *
1079
- * @param typoSupport - Rendering mode.
1080
- */
1081
- computeStyledString(typoSupport: TypoSupport): string;
1082
- }
1083
- /**
1084
- * A mutable sequence of {@link TypoString} segments forming a styled multi-part message.
1085
- * Rendering is deferred to {@link TypoText.computeStyledString}.
1086
- */
1087
- declare class TypoText {
1088
- #private;
1089
- /**
1090
- * @param typoParts - Initial segments; `TypoText` is flattened, `string` is wrapped unstyled.
1091
- */
1092
- constructor(...typoParts: Array<TypoText | TypoString | string>);
1093
- /**
1094
- * Appends a {@link TypoString} segment.
1095
- *
1096
- * @param typoString - Segment to append.
1097
- */
1098
- pushString(typoString: TypoString | string): void;
1099
- /**
1100
- * Appends all segments from another {@link TypoText} (shallow copy).
1101
- *
1102
- * @param typoText - Source text.
1103
- */
1104
- pushText(typoText: TypoText | string): void;
1105
- /**
1106
- * Renders all segments into a single styled string.
1107
- *
1108
- * @param typoSupport - Rendering mode.
1109
- * @returns Concatenated styled string.
1110
- */
1111
- computeStyledString(typoSupport: TypoSupport): string;
1112
- /**
1113
- * Returns the concatenation of all segments' raw (unstyled) text.
1114
- */
1115
- computeRawString(): string;
1116
- /**
1117
- * Returns the total character count of the raw (unstyled) text.
1118
- */
1119
- computeRawLength(): number;
1120
- }
1121
- /**
1122
- * A column-aligned grid of {@link TypoText} cells.
1123
- * Each column is padded to the widest cell (raw chars); the last column is not padded.
1124
- * Used by {@link usageToStyledLines} to render `Positionals:`, `Subcommands:`, and `Options:`.
1125
- */
1126
- declare class TypoGrid {
1127
- #private;
1128
- constructor();
1129
- /**
1130
- * Appends a row. All rows should have the same cell count for alignment to be meaningful.
1131
- *
1132
- * @param cells - Ordered {@link TypoText} cells.
1133
- */
1134
- pushRow(cells: Array<TypoText>): void;
1135
- /**
1136
- * Renders the grid as a 2-D array of styled (and column-padded) strings.
1137
- * Join each inner array with `""` to get a line.
1138
- *
1139
- * @param typoSupport - Rendering mode.
1140
- * @returns 2-D array of styled strings.
1141
- */
1142
- computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>>;
1143
- }
1144
- /**
1145
- * `Error` subclass with a {@link TypoText} styled message for rich terminal output.
1146
- * Used throughout the library for parse failures (unknown option, type decode error, etc.).
1147
- * If `source` is a `TypoError`, its styled text is chained after `": "`.
1148
- */
1149
- declare class TypoError extends Error {
1150
- #private;
1151
- /**
1152
- * @param currentTypoText - Styled message for this error.
1153
- * @param source - Optional cause; `TypoError` chains styled text, `Error` appends `.message`, else `String()`.
1154
- */
1155
- constructor(currentTypoText: TypoText, source?: unknown);
1156
- /**
1157
- * Renders the styled error message (without a `"Error:"` prefix).
1158
- *
1159
- * @param typoSupport - Rendering mode.
1160
- * @returns Styled error string.
1161
- */
1162
- computeStyledString(typoSupport: TypoSupport): string;
1163
- /**
1164
- * Runs `thrower`; on any throw wraps it as a `TypoError` with `context()` prepended.
1165
- * Useful for adding call-chain context (e.g. `"at 0: Number: ..."`).
1166
- *
1167
- * @typeParam Value - Return type of `thrower`.
1168
- * @param thrower - Function to execute; result passed through on success.
1169
- * @param context - Produces the {@link TypoText} prepended to the caught error.
1170
- * @returns Value from `thrower`.
1171
- * @throws `TypoError` wrapping the original error with context prepended.
1172
- */
1173
- static tryWithContext<Value>(thrower: () => Value, context: () => TypoText): Value;
1174
- }
1175
- /**
1176
- * Controls ANSI terminal styling for {@link TypoString}, {@link TypoText}, and error rendering.
1177
- * Create via {@link TypoSupport.none}, {@link TypoSupport.tty}, {@link TypoSupport.mock},
1178
- * or {@link TypoSupport.inferFromProcess}.
1179
- */
1180
- declare class TypoSupport {
1181
- #private;
1182
- private constructor();
1183
- /**
1184
- * Returns a `TypoSupport` that strips all styling (plain text, no ANSI codes).
1185
- */
1186
- static none(): TypoSupport;
1187
- /**
1188
- * Returns a `TypoSupport` that applies ANSI escape codes (for color-capable terminals).
1189
- */
1190
- static tty(): TypoSupport;
1191
- /**
1192
- * Returns a `TypoSupport` with deterministic textual styling for snapshot tests.
1193
- * Style flags appear as suffixes: `{text}@color`, `{text}+` (bold), `{text}-` (dim),
1194
- * `{text}*` (italic), `{text}_` (underline), `{text}~` (strikethrough).
1195
- */
1196
- static mock(): TypoSupport;
1197
- /**
1198
- * Auto-detects styling mode from the process environment.
1199
- * `FORCE_COLOR=0` / `NO_COLOR` → none; `FORCE_COLOR` (truthy) / `isTTY` → tty; else → none.
1200
- * Falls back to none if `process` is unavailable.
1201
- */
1202
- static inferFromProcess(): TypoSupport;
1203
- /**
1204
- * Applies `typoStyle` to `value` according to the current mode.
1205
- *
1206
- * @param value - Raw text.
1207
- * @param typoStyle - Style to apply.
1208
- * @returns Styled string.
1209
- */
1210
- computeStyledString(value: string, typoStyle: TypoStyle): string;
1211
- /**
1212
- * Formats any thrown value as `"Error: <message>"` with {@link typoStyleFailure} on the prefix.
1213
- *
1214
- * @param error - Any thrown value.
1215
- * @returns Styled error string.
1216
- */
1217
- computeStyledErrorMessage(error: unknown): string;
1218
- }
1219
-
1220
- /**
1221
- * Converts a {@link CommandUsage} model into an array of styled lines ready to be
1222
- * joined with `"\n"` and printed to the terminal.
1223
- *
1224
- * The output format is:
1225
- * ```
1226
- * Usage: <cliName> [segments...]
1227
- *
1228
- * <description> (<hint>)
1229
- * <detail lines...>
1230
- *
1231
- * Positionals:
1232
- * <LABEL> <description> (<hint>)
1233
- *
1234
- * Subcommands:
1235
- * <name> <description> (<hint>)
1236
- *
1237
- * Options:
1238
- * -s, --long <LABEL> <description> (<hint>)
1239
- *
1240
- * Examples:
1241
- * <description>
1242
- * <command line>
1243
- *
1244
- * ```
1245
- * Sections that have no entries are omitted. The trailing empty line is always included.
1246
- *
1247
- * Column alignment within each section is handled by {@link TypoGrid}: the widest entry
1248
- * in each column sets the width for the entire section.
1249
- *
1250
- * @param params.cliName - Program name for the usage line.
1251
- * @param params.commandUsage - From {@link CommandDecoder.generateUsage}.
1252
- * @param params.typoSupport - Rendering mode.
1253
- * @returns One string per output line; trailing empty string for the blank line at the end.
1254
- *
1255
- * @example
1256
- * ```ts
1257
- * const lines = usageToStyledLines({
1258
- * cliName: "my-cli",
1259
- * commandUsage: commandDecoder.generateUsage(),
1260
- * typoSupport: TypoSupport.tty(),
1261
- * });
1262
- * process.stdout.write(lines.join("\n"));
1263
- * ```
1264
- */
1265
- declare function usageToStyledLines(params: {
1266
- cliName: Lowercase<string>;
1267
- commandUsage: CommandUsage;
1268
- typoSupport: TypoSupport;
1269
- }): string[];
1270
-
1271
- export { type Command, type CommandDecoder, type CommandInformation, type CommandInterpreter, type CommandUsage, type CommandUsageSegment, type CommandUsageSubcommand, type Operation, type OperationDecoder, type OperationInterpreter, type OperationUsage, type Option, type OptionDecoder, type OptionUsage, type Positional, type PositionalDecoder, type PositionalUsage, ReaderArgs, type ReaderOptionKey, type ReaderOptions, type ReaderPositionals, type Type, type TypoColor, TypoError, TypoGrid, TypoString, type TypoStyle, 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 };
1233
+ export { type Command, type CommandDecoder, type CommandInformation, type CommandInterpreter, type Operation, type OperationDecoder, type OperationInterpreter, type Option, type OptionDecoder, type Positional, type PositionalDecoder, ReaderArgs, type ReaderOptionKey, type ReaderOptionParsing, type ReaderOptionValue, type ReaderOptions, type ReaderPositionals, type Type, type TypoColor, TypoError, TypoGrid, TypoString, type TypoStyle, TypoSupport, TypoText, type UsageCommand, type UsageOption, type UsagePositional, type UsageSubcommand, 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 };