cli-kiss 0.2.2 → 0.2.4

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,10 +1,5 @@
1
1
  /**
2
- * An opaque key that uniquely identifies a registered CLI option within a
3
- * {@link ReaderArgs} instance.
4
- *
5
- * Keys are returned by {@link ReaderArgs.registerOption} and passed back to
6
- * {@link ReaderArgs.getOptionValues} to retrieve the parsed values. The internal
7
- * representation is intentionally opaque — treat it as a handle, not a string.
2
+ * Opaque key returned by {@link ReaderArgs.registerOption}.
8
3
  */
9
4
  type ReaderOptionKey = (string | {
10
5
  __brand: "ReaderOptionKey";
@@ -12,185 +7,144 @@ type ReaderOptionKey = (string | {
12
7
  __brand: "ReaderOptionKey";
13
8
  };
14
9
  /**
15
- * Interface for registering and querying CLI options during argument parsing.
16
- *
17
- * {@link ReaderArgs} implements both `ReaderOptions` and {@link ReaderPositionals}.
18
- * The two interfaces are exposed separately so that option and positional parsing logic
19
- * can depend only on the capability 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>, next: 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}.
20
25
  */
21
26
  type ReaderOptions = {
22
27
  /**
23
- * Registers a new option so the parser can recognise it when scanning argument tokens.
28
+ * Registers an option; all `longs` and `shorts` share the same key.
24
29
  *
25
- * @param definition.longs - The long-form names (without `--`) for this option.
26
- * @param definition.shorts - The short-form names (without `-`) for this option.
27
- * @param definition.valued - When `true`, the option consumes the following token as
28
- * its value. When `false`, the option is a boolean flag.
29
- * @returns An opaque {@link ReaderOptionKey} used to retrieve parsed values later.
30
- * @throws `Error` if any of the given names has already been registered, or if a
31
- * short name overlaps (is a prefix of, or has as a prefix, another registered short).
30
+ * @param definition.longs - Long-form names (without `--`).
31
+ * @param definition.shorts - Short-form names (without `-`).
32
+ * @param definition.parsing - Parsing behaviour.
33
+ * @returns A {@link ReaderOptionKey} for later retrieval.
34
+ * @throws `Error` if a name is already registered or short names overlap.
32
35
  */
33
36
  registerOption(definition: {
34
37
  longs: Array<string>;
35
38
  shorts: Array<string>;
36
- valued: boolean;
39
+ parsing: ReaderOptionParsing;
37
40
  }): ReaderOptionKey;
38
41
  /**
39
- * Returns all values collected for the option identified by `key`.
40
- *
41
- * @param key - The key returned by a prior {@link ReaderOptions.registerOption} call.
42
- * @returns An array of raw string values, one per occurrence of the option on the
43
- * command line. Empty if the option was never provided.
44
- * @throws `Error` if `key` was not previously registered on this instance.
42
+ * Returns all values collected for `key`.
45
43
  */
46
- getOptionValues(key: ReaderOptionKey): Array<string>;
44
+ getOptionValues(key: ReaderOptionKey): Array<ReaderOptionValue>;
47
45
  };
48
46
  /**
49
- * Interface for consuming positional (non-option) argument tokens during parsing.
50
- *
51
- * {@link ReaderArgs} implements both {@link ReaderOptions} and `ReaderPositionals`.
47
+ * Positional consumption interface. Subset of {@link ReaderArgs}.
52
48
  */
53
49
  type ReaderPositionals = {
54
50
  /**
55
- * Consumes and returns the next positional token from the argument list, skipping
56
- * any option tokens (which are parsed as side-effects).
51
+ * Returns the next positional token, parsing intervening options as side-effects.
57
52
  *
58
- * @returns The next positional string value, or `undefined` if no more positionals
59
- * are available.
60
- * @throws {@link TypoError} if an unrecognised option token is encountered while
61
- * scanning for the next positional.
53
+ * @returns The next positional, or `undefined` when exhausted.
54
+ * @throws {@link TypoError} on an unrecognised option.
62
55
  */
63
56
  consumePositional(): string | undefined;
64
57
  };
65
58
  /**
66
- * The core argument parser for `cli-kiss`. Parses a flat array of raw CLI tokens into
67
- * named options and positional values.
59
+ * Core argument parser: converts raw CLI tokens into named options and positionals.
60
+ * Options must be registered before {@link ReaderArgs.consumePositional} is called.
68
61
  *
69
- * Options must be registered with {@link ReaderArgs.registerOption} **before**
70
- * {@link ReaderArgs.consumePositional} is called, because the parser needs to know
71
- * whether each token is an option name, an option value, or a bare positional.
62
+ * Supported syntax: `--name`, `--name value`, `--name=value`,
63
+ * `-n`, `-n value`, `-nvalue`, `-abc` (stacked), `--` (end-of-options).
72
64
  *
73
- * **Supported argument syntax:**
74
- * - Long options: `--name`, `--name value`, `--name=value`
75
- * - Short options: `-n`, `-n value`, `-n=value`, `-nvalue`, `-abc` (stacked flags)
76
- * - End-of-options separator: `--` — all subsequent tokens are treated as positionals.
77
- *
78
- * In most cases you do not need to use `ReaderArgs` directly; it is created internally
79
- * by {@link runAndExit}. It is exposed for advanced use cases such as building
80
- * custom runners.
65
+ * Created internally by {@link runAndExit}; exposed for advanced / custom runners.
81
66
  */
82
67
  declare class ReaderArgs {
83
68
  #private;
84
69
  /**
85
- * @param args - The raw command-line tokens to parse. Typically `process.argv.slice(2)`.
86
- * The array is not modified; a read cursor is maintained internally.
70
+ * @param args - Raw CLI tokens (e.g. `process.argv.slice(2)`). Not mutated.
87
71
  */
88
72
  constructor(args: ReadonlyArray<string>);
89
73
  /**
90
- * Registers a CLI option so the parser can recognise it.
91
- *
92
- * All `longs` and `shorts` are associated with the same returned key. Calling
93
- * `getOptionValues(key)` after parsing will return values collected under any of the
94
- * registered names.
95
- *
96
- * Short names support stacking (e.g. `-abc` is parsed as `-a -b -c`) and inline
97
- * values (e.g. `-nvalue`). Short names must not be a prefix of, nor have as a prefix,
98
- * any other registered short name — the parser uses prefix matching to parse stacked
99
- * shorts, so overlapping prefixes would be ambiguous.
74
+ * Registers an option; all `longs` and `shorts` share the same key.
75
+ * Short names must not be prefixes of one another.
100
76
  *
101
77
  * @param definition.longs - Long-form names (without `--`).
102
78
  * @param definition.shorts - Short-form names (without `-`).
103
- * @param definition.valued - `true` if the option consumes a value; `false` for flags.
104
- * @returns An opaque {@link ReaderOptionKey} to pass to {@link ReaderArgs.getOptionValues}.
105
- * @throws `Error` if any name is already registered or if two short names overlap.
79
+ * @param definition.parsing - Parsing behaviour.
80
+ * @returns A {@link ReaderOptionKey} for {@link ReaderArgs.getOptionValues}.
81
+ * @throws `Error` if any name is already registered or short names overlap.
106
82
  */
107
83
  registerOption(definition: {
108
84
  longs: Array<string>;
109
85
  shorts: Array<string>;
110
- valued: boolean;
86
+ parsing: ReaderOptionParsing;
111
87
  }): ReaderOptionKey;
112
88
  /**
113
- * Returns all raw string values collected for the given option key.
89
+ * Returns all values collected for `key`.
114
90
  *
115
- * @param key - A key previously returned by {@link ReaderArgs.registerOption}.
116
- * @returns An array of string values, one per occurrence on the command line. For
117
- * flags this will be `["true"]` per occurrence; for valued options it will be the
118
- * literal value strings.
119
- * @throws `Error` if `key` was not registered on this instance.
91
+ * @param key - Key from {@link ReaderArgs.registerOption}.
92
+ * @returns One entry per occurrence.
93
+ * @throws `Error` if `key` was not registered.
120
94
  */
121
- getOptionValues(key: ReaderOptionKey): Array<string>;
95
+ getOptionValues(key: ReaderOptionKey): Array<ReaderOptionValue>;
122
96
  /**
123
- * Scans forward through the argument list and returns the next bare positional token,
124
- * consuming and parsing any intervening option tokens as side-effects.
125
- *
126
- * Option tokens encountered during the scan are recorded in the internal results map
127
- * (equivalent to recording their values against their key). Any unrecognised option token
128
- * causes a {@link TypoError} to be thrown immediately.
97
+ * Returns the next positional token; parses intervening options as a side-effect.
98
+ * All tokens after `--` are treated as positionals.
129
99
  *
130
- * After `--` is encountered, all remaining tokens are treated as positionals.
131
- *
132
- * @returns The next positional string, or `undefined` when the argument list is
133
- * exhausted.
134
- * @throws {@link TypoError} if an unrecognised option (long or short) is encountered.
100
+ * @returns The next positional, or `undefined` when exhausted.
101
+ * @throws {@link TypoError} on an unrecognised option.
135
102
  */
136
103
  consumePositional(): string | undefined;
137
104
  }
138
105
 
139
106
  /**
140
- * Describes how to decode a raw CLI string token into a typed TypeScript value.
141
- *
142
- * A `Type` is a pair of:
143
- * - a `content` string — a human-readable name shown in help/error messages (e.g.
144
- * `"String"`, `"Number"`, `"Url"`).
145
- * - a `decoder` function — converts the raw string or throws a {@link TypoError} on
146
- * invalid input.
107
+ * Decodes a raw CLI string into a typed value.
108
+ * A pair of a human-readable `content` name (e.g. `"Number"`) and a `decoder` function.
147
109
  *
148
- * Built-in types: {@link typeString}, {@link typeBoolean}, {@link typeNumber},
110
+ * Built-in: {@link typeString}, {@link typeBoolean}, {@link typeNumber},
149
111
  * {@link typeInteger}, {@link typeDate}, {@link typeUrl}.
112
+ * Composite: {@link typeOneOf}, {@link typeMapped}, {@link typeTuple}, {@link typeList}.
150
113
  *
151
- * Composite types: {@link typeOneOf}, {@link typeConverted}, {@link typeTuple},
152
- * {@link typeList}.
153
- *
154
- * @typeParam Value - The TypeScript type that the decoder produces.
114
+ * @typeParam Value - Type produced by the decoder.
155
115
  */
156
116
  type Type<Value> = {
157
117
  /**
158
- * Human-readable name for this type, used in help text and error messages.
159
- * Examples: `"String"`, `"Number"`, `"Url"`.
118
+ * Human-readable name shown in help and errors (e.g. `"String"`, `"Number"`).
160
119
  */
161
120
  content: string;
162
121
  /**
163
- * Decodes a raw string token into a `Value`.
122
+ * Decodes a raw CLI string into `Value`.
164
123
  *
165
- * @param value - The raw string from the command line.
124
+ * @param input - Raw string from the command line.
166
125
  * @returns The decoded value.
167
- * @throws {@link TypoError} if the value cannot be decoded.
126
+ * @throws {@link TypoError} on invalid input.
168
127
  */
169
- decoder(value: string): Value;
128
+ decoder(input: string): Value;
170
129
  };
171
130
  /**
172
- * A {@link Type} that decodes `"true"` / `"yes"` to `true` and `"false"` / `"no"` to
173
- * `false` (case-insensitive). Any other value throws a {@link TypoError}.
174
- *
175
- * Primarily used internally by {@link optionFlag} for the `--flag=<value>` syntax, but
176
- * can also be used in positionals or valued options.
131
+ * Decodes a string to `boolean` (case-insensitive).
132
+ * Used by {@link optionFlag} for `--flag=<value>`.
177
133
  *
178
134
  * @example
179
135
  * ```ts
136
+ * typeBoolean.decoder("true") // → true
180
137
  * typeBoolean.decoder("yes") // → true
138
+ * typeBoolean.decoder("y") // → true
181
139
  * typeBoolean.decoder("false") // → false
182
- * typeBoolean.decoder("1") // throws TypoError
140
+ * typeBoolean.decoder("no") // false
141
+ * typeBoolean.decoder("n") // → false
183
142
  * ```
184
143
  */
185
144
  declare const typeBoolean: Type<boolean>;
186
145
  /**
187
- * A {@link Type} that parses a date/time string using `Date.parse`.
188
- *
189
- * Accepts any format supported by the JavaScript `Date.parse` API, including ISO 8601
190
- * strings (e.g. `"2024-01-15"`, `"2024-01-15T10:30:00Z"`). Non-parseable values throw
191
- * a {@link TypoError}.
192
- *
193
- * Produces a `Date` object. The decoded value is the result of `new Date(Date.parse(value))`.
146
+ * Parses a date/time string via `Date.parse`.
147
+ * Accepts any format supported by `Date.parse`, including ISO 8601.
194
148
  *
195
149
  * @example
196
150
  * ```ts
@@ -201,11 +155,7 @@ declare const typeBoolean: Type<boolean>;
201
155
  */
202
156
  declare const typeDate: Type<Date>;
203
157
  /**
204
- * A {@link Type} that parses a string into a JavaScript `number` using the `Number()`
205
- * constructor.
206
- *
207
- * Accepts integers, floating-point values, and scientific notation (e.g. `"3.14"`,
208
- * `"-1"`, `"1e10"`). Values that produce `NaN` throw a {@link TypoError}.
158
+ * Parses a string to `number` via `Number()`; `NaN` throws {@link TypoError}.
209
159
  *
210
160
  * @example
211
161
  * ```ts
@@ -216,11 +166,8 @@ declare const typeDate: Type<Date>;
216
166
  */
217
167
  declare const typeNumber: Type<number>;
218
168
  /**
219
- * A {@link Type} that parses a string into a JavaScript `bigint` using the `BigInt()`
220
- * constructor.
221
- *
222
- * Only accepts valid integer strings (e.g. `"42"`, `"-100"`, `"9007199254740993"`).
223
- * Floating-point strings or non-numeric values throw a {@link TypoError}.
169
+ * Parses an integer string to `bigint` via `BigInt()`.
170
+ * Floats and non-numeric strings throw {@link TypoError}.
224
171
  *
225
172
  * @example
226
173
  * ```ts
@@ -231,10 +178,8 @@ declare const typeNumber: Type<number>;
231
178
  */
232
179
  declare const typeInteger: Type<bigint>;
233
180
  /**
234
- * A {@link Type} that parses a string into a `URL` object using the `URL` constructor.
235
- *
236
- * The string must be a valid absolute URL (e.g. `"https://example.com/path?q=1"`).
237
- * Relative URLs and malformed strings throw a {@link TypoError}.
181
+ * Parses an absolute URL string to a `URL` object.
182
+ * Relative or malformed URLs throw {@link TypoError}.
238
183
  *
239
184
  * @example
240
185
  * ```ts
@@ -244,9 +189,7 @@ declare const typeInteger: Type<bigint>;
244
189
  */
245
190
  declare const typeUrl: Type<URL>;
246
191
  /**
247
- * A {@link Type} that passes the raw string through unchanged (identity decoder).
248
- *
249
- * This is the simplest type and accepts any string value without validation.
192
+ * Identity decoder passes the raw string through unchanged.
250
193
  *
251
194
  * @example
252
195
  * ```ts
@@ -256,29 +199,21 @@ declare const typeUrl: Type<URL>;
256
199
  */
257
200
  declare const typeString: Type<string>;
258
201
  /**
259
- * Creates a new {@link Type} by chaining a `before` type decoder with an `after`
260
- * transformation.
261
- *
262
- * The raw string is first decoded by `before.decoder`; its result is then passed to
263
- * `after.decoder`. Errors from `before` are wrapped with a "from: <content>" context
264
- * prefix so that the full decoding path is visible in error messages.
202
+ * Chains `before`'s decoder with an `after` transformation.
203
+ * `before` errors are prefixed with `"from: <content>"` for traceability.
265
204
  *
266
- * Use this when an existing type (e.g. {@link typeString}, {@link typeOneOf}) produces
267
- * an intermediate value that needs a further transformation (e.g. parsing a
268
- * string-keyed enum into a number).
205
+ * @typeParam Before - Intermediate type from `before.decoder`.
206
+ * @typeParam After - Final type from `after.decoder`.
269
207
  *
270
- * @typeParam Before - The intermediate type produced by `before.decoder`.
271
- * @typeParam After - The final type produced by `after.decoder`.
272
- *
273
- * @param before - The base type that decodes the raw CLI string.
274
- * @param after - The transformation applied to the `Before` value.
275
- * @param after.content - Human-readable name for the resulting type (shown in errors).
276
- * @param after.decoder - Function that converts a `Before` value into `After`.
277
- * @returns A new {@link Type}`<After>` whose `content` is `after.content`.
208
+ * @param before - Base decoder for the raw string.
209
+ * @param after - Transformation applied to the decoded value.
210
+ * @param after.content - Name for the resulting type (shown in errors).
211
+ * @param after.decoder - Converts a `Before` value to `After`.
212
+ * @returns A {@link Type}`<After>`.
278
213
  *
279
214
  * @example
280
215
  * ```ts
281
- * const typePort = typeConverted(typeNumber, {
216
+ * const typePort = typeMapped(typeNumber, {
282
217
  * content: "Port",
283
218
  * decoder: (n) => {
284
219
  * if (n < 1 || n > 65535) throw new Error("Out of range");
@@ -289,23 +224,17 @@ declare const typeString: Type<string>;
289
224
  * // "--port 99999" → TypoError: --port: <PORT>: Port: Out of range
290
225
  * ```
291
226
  */
292
- declare function typeConverted<Before, After>(before: Type<Before>, after: {
227
+ declare function typeMapped<Before, After>(before: Type<Before>, after: {
293
228
  content: string;
294
229
  decoder: (value: Before) => After;
295
230
  }): Type<After>;
296
231
  /**
297
- * Creates a {@link Type}`<string>` that only accepts a fixed set of string values.
298
- *
299
- * The decoder performs an exact (case-sensitive) lookup in `values`. If the input is
300
- * not in the set, a {@link TypoError} is thrown listing up to 5 of the valid options.
232
+ * Creates a {@link Type}`<string>` that only accepts a fixed set of values.
233
+ * Out-of-set inputs throw {@link TypoError} listing up to 5 valid options.
301
234
  *
302
- * Combine with {@link typeConverted} to map the accepted strings to a richer type.
303
- *
304
- * @param content - Human-readable name for this type shown in help text and error
305
- * messages (e.g. `"Environment"`, `"LogLevel"`).
306
- * @param values - The ordered list of accepted string values. The order is preserved in
307
- * the error message preview.
308
- * @returns A {@link Type}`<string>` that validates membership in `values`.
235
+ * @param content - Name shown in help and errors (e.g. `"Environment"`).
236
+ * @param values - Ordered list of accepted values.
237
+ * @returns A {@link Type}`<string>`.
309
238
  *
310
239
  * @example
311
240
  * ```ts
@@ -314,25 +243,16 @@ declare function typeConverted<Before, After>(before: Type<Before>, after: {
314
243
  * typeEnv.decoder("unknown") // throws TypoError: Invalid value: "unknown" (expected one of: "dev" | "staging" | "prod")
315
244
  * ```
316
245
  */
317
- declare function typeOneOf(content: string, values: Array<string>): Type<string>;
246
+ declare function typeOneOf<const Value extends string>(content: string, values: Array<Value>): Type<Value>;
318
247
  /**
319
- * Creates a {@link Type} that decodes a single delimited string into a fixed-length
320
- * tuple of typed elements.
321
- *
322
- * The raw string is split on `separator` into exactly `elementTypes.length` parts.
323
- * Each part is decoded by its corresponding element type. If the number of splits does
324
- * not match, or if any element's decoder fails, a {@link TypoError} is thrown with the
325
- * index and element type context.
248
+ * Splits a delimited string into a typed tuple.
249
+ * Each part is decoded by the corresponding element type; wrong count or decode failure throws {@link TypoError}.
326
250
  *
327
- * The resulting `content` is the element types' `content` values joined by `separator`
328
- * (e.g. `"Number,String"` for a `[number, string]` tuple with `","` separator).
251
+ * @typeParam Elements - Tuple of decoded value types (inferred from `elementTypes`).
329
252
  *
330
- * @typeParam Elements - The tuple type of decoded element values (inferred from
331
- * `elementTypes`).
332
- *
333
- * @param elementTypes - An ordered array of {@link Type}s, one per tuple element.
334
- * @param separator - The string used to split the raw value (default: `","`).
335
- * @returns A {@link Type}`<Elements>` tuple type.
253
+ * @param elementTypes - One {@link Type} per tuple element, in order.
254
+ * @param separator - Delimiter (default `","`).
255
+ * @returns A {@link Type}`<Elements>`.
336
256
  *
337
257
  * @example
338
258
  * ```ts
@@ -346,26 +266,14 @@ declare function typeTuple<const Elements extends Array<any>>(elementTypes: {
346
266
  [K in keyof Elements]: Type<Elements[K]>;
347
267
  }, separator?: string): Type<Elements>;
348
268
  /**
349
- * Creates a {@link Type} that decodes a single delimited string into an array of
350
- * homogeneous typed elements.
351
- *
352
- * The raw string is split on `separator` and each part is decoded by `elementType`.
353
- * If any element's decoder fails, a {@link TypoError} is thrown with the index and
354
- * element type context.
355
- *
356
- * Unlike {@link typeTuple}, the number of elements is not fixed; the result array
357
- * length equals the number of `separator`-delimited parts in the input string. To pass
358
- * an empty array, the user must pass an empty string (`""`), which splits into one
359
- * empty-string element — consider using {@link optionRepeatable} instead if you want a
360
- * naturally empty default.
361
- *
362
- * The `content` is formatted as `"<elementContent>[<sep><elementContent>]..."` to
363
- * signal repeatability.
269
+ * Splits a delimited string into a typed array.
270
+ * Each part is decoded by `elementType`; failed decodes throw {@link TypoError}.
271
+ * Note: splitting an empty string yields one empty element — prefer {@link optionRepeatable} for a zero-default.
364
272
  *
365
- * @typeParam Value - The TypeScript element type produced by `elementType.decoder`.
273
+ * @typeParam Value - Element type produced by `elementType.decoder`.
366
274
  *
367
- * @param elementType - The {@link Type} used to decode each element.
368
- * @param separator - The string used to split the raw value (default: `","`).
275
+ * @param elementType - Decoder applied to each element.
276
+ * @param separator - Delimiter (default `","`).
369
277
  * @returns A {@link Type}`<Array<Value>>`.
370
278
  *
371
279
  * @example
@@ -381,86 +289,423 @@ declare function typeTuple<const Elements extends Array<any>>(elementTypes: {
381
289
  declare function typeList<Value>(elementType: Type<Value>, separator?: string): Type<Array<Value>>;
382
290
 
383
291
  /**
384
- * Describes a single CLI option (a flag or a valued option) together with its parsing
385
- * and usage-generation logic.
386
- *
387
- * Options are created with {@link optionFlag}, {@link optionSingleValue}, or
388
- * {@link optionRepeatable} and are passed via the `options` map of {@link operation}.
389
- *
390
- * @typeParam Value - The TypeScript type of the parsed option value.
391
- * - `boolean` for flags created with {@link optionFlag}.
392
- * - `T` for single-value options created with {@link optionSingleValue}.
393
- * - `Array<T>` for repeatable options created with {@link optionRepeatable}.
292
+ * Color names for terminal styling, used by {@link TypoStyle}.
293
+ * `dark*` = standard ANSI (30–37); `bright*` = high-intensity (90–97).
394
294
  */
395
- type Option<Value> = {
396
- /** Returns human-readable metadata used to render the `Options:` section of help. */
397
- generateUsage(): OptionUsage;
295
+ type TypoColor = "darkBlack" | "darkRed" | "darkGreen" | "darkYellow" | "darkBlue" | "darkMagenta" | "darkCyan" | "darkWhite" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
296
+ /**
297
+ * Visual styling applied by a {@link TypoSupport} instance.
298
+ * All fields are optional; ignored entirely in `"none"` mode.
299
+ */
300
+ type TypoStyle = {
301
+ /**
302
+ * Foreground (text) color.
303
+ */
304
+ fgColor?: TypoColor;
305
+ /**
306
+ * Background color.
307
+ */
308
+ bgColor?: TypoColor;
309
+ /**
310
+ * Reduced intensity.
311
+ */
312
+ dim?: boolean;
313
+ /**
314
+ * Bold.
315
+ */
316
+ bold?: boolean;
317
+ /**
318
+ * Italic.
319
+ */
320
+ italic?: boolean;
321
+ /**
322
+ * Underline.
323
+ */
324
+ underline?: boolean;
325
+ /**
326
+ * Strikethrough.
327
+ */
328
+ strikethrough?: boolean;
329
+ };
330
+ /**
331
+ * Section title style. Bold dark-green.
332
+ */
333
+ declare const typoStyleTitle: TypoStyle;
334
+ /**
335
+ * Logic/type identifier style. Bold dark-magenta.
336
+ */
337
+ declare const typoStyleLogic: TypoStyle;
338
+ /**
339
+ * Quoted user-input style. Bold dark-yellow.
340
+ */
341
+ declare const typoStyleQuote: TypoStyle;
342
+ /**
343
+ * Error label style. Bold dark-red.
344
+ */
345
+ declare const typoStyleFailure: TypoStyle;
346
+ /**
347
+ * Option/command name style. Bold dark-cyan.
348
+ */
349
+ declare const typoStyleConstants: TypoStyle;
350
+ /**
351
+ * Positional/user-input label style. Bold dark-blue.
352
+ */
353
+ declare const typoStyleUserInput: TypoStyle;
354
+ /**
355
+ * Strong text style. Bold.
356
+ */
357
+ declare const typoStyleRegularStrong: TypoStyle;
358
+ /**
359
+ * Subtle text style. Italic and dim.
360
+ */
361
+ declare const typoStyleRegularWeaker: TypoStyle;
362
+ /**
363
+ * Immutable styled string segment. Compose into a {@link TypoText}.
364
+ */
365
+ declare class TypoString {
366
+ #private;
367
+ /**
368
+ * @param value - Raw text content.
369
+ * @param typoStyle - Style to apply when rendering. Defaults to `{}` (no style).
370
+ */
371
+ constructor(value: string, typoStyle?: TypoStyle);
372
+ /**
373
+ * Returns the text styled by `typoSupport`.
374
+ *
375
+ * @param typoSupport - Rendering mode.
376
+ */
377
+ computeStyledString(typoSupport: TypoSupport): string;
378
+ /**
379
+ * Returns the raw text.
380
+ */
381
+ getRawString(): string;
382
+ }
383
+ /**
384
+ * Mutable sequence of {@link TypoString} segments.
385
+ */
386
+ declare class TypoText {
387
+ #private;
398
388
  /**
399
- * Registers the option on `readerOptions` so the argument reader recognises it, and
400
- * returns an {@link OptionParser} that can later retrieve the parsed value(s).
389
+ * @param segments - Initial text segments
390
+ */
391
+ constructor(...segments: Array<TypoText | Array<TypoString> | TypoString | string>);
392
+ /**
393
+ * Appends new text segment(s).
401
394
  *
402
- * @param readerOptions - The shared {@link ReaderArgs} that will parse the raw
403
- * command-line tokens.
395
+ * @param segment - Text segment(s) to append.
396
+ */
397
+ push(segment: TypoText | Array<TypoString> | TypoString | string): void;
398
+ /**
399
+ * Renders all segments into a single styled string.
400
+ *
401
+ * @param typoSupport - Rendering mode.
402
+ * @returns Concatenated styled string.
403
+ */
404
+ computeStyledString(typoSupport: TypoSupport): string;
405
+ /**
406
+ * Returns the concatenated raw text.
404
407
  */
405
- createParser(readerOptions: ReaderArgs): OptionParser<Value>;
408
+ computeRawString(): string;
409
+ /**
410
+ * Returns the total raw character count.
411
+ */
412
+ computeRawLength(): number;
413
+ }
414
+ /**
415
+ * Column-aligned grid of {@link TypoText} cells.
416
+ * Each column is padded to the widest cell (raw chars); the last column is not padded.
417
+ */
418
+ declare class TypoGrid {
419
+ #private;
420
+ constructor();
421
+ /**
422
+ * Appends a row. All rows should have the same cell count.
423
+ *
424
+ * @param cells - Ordered {@link TypoText} cells.
425
+ */
426
+ pushRow(cells: Array<TypoText>): void;
427
+ /**
428
+ * Renders as an array of styled, column-padded strings.
429
+ *
430
+ * @param typoSupport - Rendering mode.
431
+ * @returns 2-D array of styled strings.
432
+ */
433
+ computeStyledLines(typoSupport: TypoSupport): Array<string>;
434
+ }
435
+ /**
436
+ * `Error` subclass with a {@link TypoText} styled message for rich terminal output.
437
+ * Chains `TypoError` sources after `": "`.
438
+ */
439
+ declare class TypoError extends Error {
440
+ #private;
441
+ /**
442
+ * @param currentTypoText - Styled message for this error.
443
+ * @param source - Optional cause; `TypoError` chains styled text, `Error` appends `.message`, else `String()`.
444
+ */
445
+ constructor(currentTypoText: TypoText, source?: unknown);
446
+ /**
447
+ * Renders the styled message (without `"Error:"` prefix).
448
+ *
449
+ * @param typoSupport - Rendering mode.
450
+ * @returns Styled error string.
451
+ */
452
+ computeStyledString(typoSupport: TypoSupport): string;
453
+ /**
454
+ * Runs `thrower`; wraps any thrown error as a `TypoError` with `context()` prepended.
455
+ *
456
+ * @typeParam Value - Return type of `thrower`.
457
+ * @param thrower - Function to execute; result passed through on success.
458
+ * @param context - Produces the {@link TypoText} prepended to the caught error.
459
+ * @returns Value from `thrower`.
460
+ * @throws `TypoError` wrapping the original error with context prepended.
461
+ */
462
+ static tryWithContext<Value>(thrower: () => Value, context: () => TypoText): Value;
463
+ }
464
+ /**
465
+ * Controls ANSI terminal styling. Create via the static factory methods.
466
+ */
467
+ declare class TypoSupport {
468
+ #private;
469
+ private constructor();
470
+ /**
471
+ * Plain text — no ANSI codes.
472
+ */
473
+ static none(): TypoSupport;
474
+ /**
475
+ * ANSI escape codes for color terminals.
476
+ */
477
+ static tty(): TypoSupport;
478
+ /**
479
+ * Deterministic textual styling for snapshot tests.
480
+ * Style flags appear as suffixes: `{text}@color`, `{text}+` (bold), `{text}-` (dim),
481
+ * `{text}*` (italic), `{text}_` (underline), `{text}~` (strikethrough).
482
+ */
483
+ static mock(): TypoSupport;
484
+ /**
485
+ * Auto-detects styling mode from the process environment.
486
+ * `FORCE_COLOR=0` / `NO_COLOR` → none; `FORCE_COLOR` (truthy) / `isTTY` → tty; else → none.
487
+ * Falls back to none if `process` is unavailable.
488
+ */
489
+ static inferFromProcess(): TypoSupport;
490
+ /**
491
+ * Applies `typoStyle` to `value` according to the current mode.
492
+ *
493
+ * @param value - Raw text.
494
+ * @param typoStyle - Style to apply.
495
+ * @returns Styled string.
496
+ */
497
+ computeStyledString(value: string, typoStyle: TypoStyle): string;
498
+ /**
499
+ * Formats any thrown value as `"Error: <message>"` with {@link typoStyleFailure} on the prefix.
500
+ *
501
+ * @param error - Any thrown value.
502
+ * @returns Styled error string.
503
+ */
504
+ computeStyledErrorMessage(error: unknown): string;
505
+ }
506
+
507
+ /**
508
+ * Usage model. Produced by {@link CommandDecoder.generateUsage}, consumed by {@link usageToStyledLines}.
509
+ */
510
+ type UsageCommand = {
511
+ /**
512
+ * Segments of the usage line
513
+ * (e.g. `my-cli <POSITIONAL> subcommand <ANOTHER_POSITIONAL>`).
514
+ */
515
+ segments: Array<UsageSegment>;
516
+ /**
517
+ * Command metadata.
518
+ */
519
+ information: CommandInformation;
520
+ /**
521
+ * Positionals in declaration order.
522
+ */
523
+ positionals: Array<UsagePositional>;
524
+ /**
525
+ * Subcommands, populated when none was selected.
526
+ */
527
+ subcommands: Array<UsageSubcommand>;
528
+ /**
529
+ * Options in registration order.
530
+ */
531
+ options: Array<UsageOption>;
406
532
  };
407
533
  /**
408
- * Retrieves the parsed value for a registered option after argument parsing is complete.
409
- *
410
- * Returned by {@link Option.createParser} and called by {@link OperationFactory.createInstance}.
411
- *
412
- * @typeParam Value - The TypeScript type of the parsed value.
534
+ * One segment of the usage line.
413
535
  */
414
- type OptionParser<Value> = {
415
- parseValue(): Value;
536
+ type UsageSegment = {
537
+ positional: string;
538
+ } | {
539
+ subcommand: string;
416
540
  };
417
541
  /**
418
- * Human-readable metadata for a single CLI option, used to render the `Options:` section
419
- * of the help output produced by {@link usageToStyledLines}.
542
+ * Usage metadata. Produced by {@link Operation.generateUsage}, consumed when building {@link UsageCommand}.
420
543
  */
421
- type OptionUsage = {
422
- /** Short description of what the option does. */
544
+ type UsageOperation = {
545
+ /**
546
+ * Registered options.
547
+ */
548
+ options: Array<UsageOption>;
549
+ /**
550
+ * Declared positionals, in order.
551
+ */
552
+ positionals: Array<UsagePositional>;
553
+ };
554
+ /**
555
+ * Positional metadata for the `Positionals:` section of help.
556
+ */
557
+ type UsagePositional = {
558
+ /**
559
+ * Help text.
560
+ */
423
561
  description: string | undefined;
424
562
  /**
425
- * Optional supplementary note shown in parentheses next to the description.
426
- * Suitable for short caveats such as `"required"` or `"defaults to 42"`.
563
+ * Short note shown in parentheses.
427
564
  */
428
565
  hint: string | undefined;
429
566
  /**
430
- * The primary long-form name of the option, without the `--` prefix (e.g. `"verbose"`).
431
- * The user passes this as `--verbose` on the command line.
567
+ * Placeholder label shown in the usage line and the `Positionals:` section.
568
+ * Required: `<NAME>`, optional: `[NAME]`, variadic: `[NAME]...`.
432
569
  */
433
- long: Lowercase<string>;
570
+ label: Uppercase<string>;
571
+ };
572
+ /**
573
+ * Entry in the `Subcommands:` section.
574
+ */
575
+ type UsageSubcommand = {
576
+ /**
577
+ * Token the user types (e.g. `"deploy"`).
578
+ */
579
+ name: string;
434
580
  /**
435
- * The optional short-form name of the option, without the `-` prefix (e.g. `"v"`).
436
- * The user passes this as `-v` on the command line.
581
+ * From {@link CommandInformation.description}.
582
+ */
583
+ description: string | undefined;
584
+ /**
585
+ * From {@link CommandInformation.hint}.
586
+ */
587
+ hint: string | undefined;
588
+ };
589
+ /**
590
+ * Option metadata for the `Options:` section of help.
591
+ */
592
+ type UsageOption = {
593
+ /**
594
+ * Short-form name without `-` (e.g. `"v"`).
437
595
  */
438
596
  short: string | undefined;
439
597
  /**
440
- * The value placeholder label shown after the long option name in the help output
441
- * (e.g. `"<FILE>"`). `undefined` for flags that take no value.
598
+ * Long-form name without `--` (e.g. `"verbose"`).
599
+ */
600
+ long: Lowercase<string>;
601
+ /**
602
+ * Extra annotation appended to the option label in help (e.g. `[=no]`, ` [*]`).
603
+ */
604
+ annotation: string | undefined;
605
+ /**
606
+ * Help text.
607
+ */
608
+ description: string | undefined;
609
+ /**
610
+ * Short note shown in parentheses.
611
+ */
612
+ hint: string | undefined;
613
+ /**
614
+ * Value placeholder in help (e.g. `"<FILE>"`). `undefined` for flags.
615
+ */
616
+ label: Uppercase<string> | undefined;
617
+ };
618
+ /**
619
+ * Converts a {@link UsageCommand} model into an array of styled lines ready to be
620
+ * joined with `"\n"` and printed to the terminal.
621
+ *
622
+ * The output format is:
623
+ * ```
624
+ * Usage: <cliName> [segments...]
625
+ *
626
+ * <description> (<hint>)
627
+ * <detail lines...>
628
+ *
629
+ * Positionals:
630
+ * <LABEL> <description> (<hint>)
631
+ *
632
+ * Subcommands:
633
+ * <name> <description> (<hint>)
634
+ *
635
+ * Options:
636
+ * -s, --long <LABEL><annotation> <description> (<hint>)
637
+ *
638
+ * Examples:
639
+ * <description>
640
+ * <command line>
641
+ *
642
+ * ```
643
+ * Sections that have no entries are omitted. The trailing empty line is always included.
644
+ *
645
+ * Column alignment per section via {@link TypoGrid}.
646
+ *
647
+ * @param params.cliName - Program name for the usage line.
648
+ * @param params.usage - From {@link CommandDecoder.generateUsage}.
649
+ * @param params.typoSupport - Rendering mode.
650
+ * @returns Styled lines; includes a trailing empty string.
651
+ *
652
+ * @example
653
+ * ```ts
654
+ * const lines = usageToStyledLines({
655
+ * cliName: "my-cli",
656
+ * usage: commandDecoder.generateUsage(),
657
+ * typoSupport: TypoSupport.tty(),
658
+ * });
659
+ * process.stdout.write(lines.join("\n"));
660
+ * ```
661
+ */
662
+ declare function usageToStyledLines(params: {
663
+ cliName: Lowercase<string>;
664
+ usage: UsageCommand;
665
+ typoSupport: TypoSupport;
666
+ }): string[];
667
+
668
+ /**
669
+ * A CLI option. Created with {@link optionFlag}, {@link optionSingleValue},
670
+ * or {@link optionRepeatable}.
671
+ *
672
+ * @typeParam Value - Decoded value type.
673
+ */
674
+ type Option<Value> = {
675
+ /**
676
+ * Returns metadata for the `Options:` section.
677
+ */
678
+ generateUsage(): UsageOption;
679
+ /**
680
+ * Registers the option on `readerOptions` and returns an {@link OptionDecoder}.
681
+ */
682
+ registerAndMakeDecoder(readerOptions: ReaderArgs): OptionDecoder<Value>;
683
+ };
684
+ /**
685
+ * Produced by {@link Option.registerAndMakeDecoder}.
686
+ *
687
+ * @typeParam Value - Decoded value type.
688
+ */
689
+ type OptionDecoder<Value> = {
690
+ /**
691
+ * Returns the decoded option value.
692
+ *
693
+ * @throws {@link TypoError} if decoding failed.
442
694
  */
443
- label: Uppercase<string> | undefined;
695
+ getAndDecodeValue(): Value;
444
696
  };
445
697
  /**
446
- * Creates a boolean flag option an option that the user passes without a value (e.g.
447
- * `--verbose`) to signal `true`, or can explicitly set with `--flag=true` / `--flag=no`.
448
- *
449
- * **Parsing rules:**
450
- * - Absent → `false` (or the return value of `default()` when provided).
451
- * - `--flag` / `--flag=true` / `--flag=yes` → `true`.
452
- * - `--flag=false` / `--flag=no` → `false`.
453
- * - Specified more than once → {@link TypoError} ("Must not be set multiple times").
454
- *
455
- * @param definition - Configuration for the flag.
456
- * @param definition.long - Primary long-form name (without `--`). Must be lowercase.
457
- * @param definition.short - Optional short-form name (without `-`).
458
- * @param definition.description - Human-readable description for the help output.
459
- * @param definition.hint - Optional supplementary note shown in parentheses.
460
- * @param definition.aliases - Additional long/short names that the parser also
461
- * recognises as this flag.
462
- * @param definition.default - Factory for the default value when the flag is absent.
463
- * Defaults to `() => false` when omitted.
698
+ * Creates a boolean flag option (`--verbose`, optionally `--flag=no`).
699
+ *
700
+ * Parsing: absent → `false`; `--flag` / `--flag=yes` → `true`; `--flag=no` → `false`;
701
+ * specified more than once → {@link TypoError}.
702
+ *
703
+ * @param definition.long - Long-form name (without `--`).
704
+ * @param definition.short - Short-form name (without `-`).
705
+ * @param definition.description - Help text.
706
+ * @param definition.hint - Short note shown in parentheses.
707
+ * @param definition.aliases - Additional names.
708
+ * @param definition.default - Default when absent. Defaults to `false`.
464
709
  * @returns An {@link Option}`<boolean>`.
465
710
  *
466
711
  * @example
@@ -481,35 +726,24 @@ declare function optionFlag(definition: {
481
726
  longs?: Array<Lowercase<string>>;
482
727
  shorts?: Array<string>;
483
728
  };
484
- default?: () => boolean;
729
+ default?: boolean;
485
730
  }): Option<boolean>;
486
731
  /**
487
- * Creates an option that accepts exactly one value (e.g. `--output dist/` or
488
- * `--output=dist/`).
489
- *
490
- * **Parsing rules:**
491
- * - Absent → `definition.default()` is called. If the default factory throws, a
492
- * {@link TypoError} is produced.
493
- * - Specified once → the value is decoded with `definition.type`.
494
- * - Specified more than once → {@link TypoError} ("Requires a single value, but got
495
- * multiple").
496
- *
497
- * **Value syntax:** `--long value`, `--long=value`, or (if `short` is set) `-s value`,
498
- * `-s=value`, or `-svalue`.
499
- *
500
- * @typeParam Value - The TypeScript type produced by the type decoder.
501
- *
502
- * @param definition - Configuration for the option.
503
- * @param definition.long - Primary long-form name (without `--`). Must be lowercase.
504
- * @param definition.short - Optional short-form name (without `-`).
505
- * @param definition.description - Human-readable description for the help output.
506
- * @param definition.hint - Optional supplementary note shown in parentheses.
507
- * @param definition.aliases - Additional long/short names the parser also recognises.
508
- * @param definition.label - Custom label shown in the help output (e.g. `"FILE"`).
509
- * Defaults to the uppercased `type.content`.
510
- * @param definition.type - The {@link Type} used to decode the raw string value.
511
- * @param definition.default - Factory for the default value when the option is absent.
512
- * Throw an error from this factory to make the option effectively required.
732
+ * Creates an option that accepts exactly one value (e.g. `--output dist/`).
733
+ *
734
+ * Parsing: absent → `default()`; once → decoded with `type`; more than once → {@link TypoError}.
735
+ * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.
736
+ *
737
+ * @typeParam Value - Type produced by the decoder.
738
+ *
739
+ * @param definition.long - Long-form name (without `--`).
740
+ * @param definition.short - Short-form name (without `-`).
741
+ * @param definition.description - Help text.
742
+ * @param definition.hint - Short note shown in parentheses.
743
+ * @param definition.aliases - Additional names.
744
+ * @param definition.label - Value placeholder in help. Defaults to uppercased `type.content`.
745
+ * @param definition.type - Decoder for the raw string value.
746
+ * @param definition.default - Default when absent. Throw to make the option required.
513
747
  * @returns An {@link Option}`<Value>`.
514
748
  *
515
749
  * @example
@@ -538,30 +772,20 @@ declare function optionSingleValue<Value>(definition: {
538
772
  default: () => Value;
539
773
  }): Option<Value>;
540
774
  /**
541
- * Creates an option that can be specified any number of times, collecting all provided
542
- * values into an array (e.g. `--file a.ts --file b.ts`).
543
- *
544
- * **Parsing rules:**
545
- * - Absent → empty array `[]`.
546
- * - Specified N times array of N decoded values, in the order they appear on the
547
- * command line.
548
- * - Each occurrence is decoded independently with `definition.type`.
549
- *
550
- * **Value syntax:** `--long value`, `--long=value`, or (if `short` is set) `-s value`,
551
- * `-s=value`, or `-svalue`.
552
- *
553
- * @typeParam Value - The TypeScript type produced by the type decoder for each
554
- * occurrence.
555
- *
556
- * @param definition - Configuration for the option.
557
- * @param definition.long - Primary long-form name (without `--`). Must be lowercase.
558
- * @param definition.short - Optional short-form name (without `-`).
559
- * @param definition.description - Human-readable description for the help output.
560
- * @param definition.hint - Optional supplementary note shown in parentheses.
561
- * @param definition.aliases - Additional long/short names the parser also recognises.
562
- * @param definition.label - Custom label shown in the help output (e.g. `"FILE"`).
563
- * Defaults to the uppercased `type.content`.
564
- * @param definition.type - The {@link Type} used to decode each raw string value.
775
+ * Creates an option that collects every occurrence into an array (e.g. `--file a.ts --file b.ts`).
776
+ *
777
+ * Parsing: absent → `[]`; N occurrences → array of N decoded values in order.
778
+ * Value syntax: `--long value`, `--long=value`, `-s value`, `-s=value`, `-svalue`.
779
+ *
780
+ * @typeParam Value - Type produced by the decoder for each occurrence.
781
+ *
782
+ * @param definition.long - Long-form name (without `--`).
783
+ * @param definition.short - Short-form name (without `-`).
784
+ * @param definition.description - Help text.
785
+ * @param definition.hint - Short note shown in parentheses.
786
+ * @param definition.aliases - Additional names.
787
+ * @param definition.label - Value placeholder in help. Defaults to uppercased `type.content`.
788
+ * @param definition.type - Decoder applied to each raw string value.
565
789
  * @returns An {@link Option}`<Array<Value>>`.
566
790
  *
567
791
  * @example
@@ -590,80 +814,45 @@ declare function optionRepeatable<Value>(definition: {
590
814
  }): Option<Array<Value>>;
591
815
 
592
816
  /**
593
- * Describes a single positional argument a bare (non-option) token on the command
594
- * line together with its parsing and usage-generation logic.
817
+ * A positional argument. Created with {@link positionalRequired}, {@link positionalOptional},
818
+ * or {@link positionalVariadics}.
595
819
  *
596
- * Positionals are created with {@link positionalRequired}, {@link positionalOptional}, or
597
- * {@link positionalVariadics} and are passed via the `positionals` array of
598
- * {@link operation}, where they are consumed in declaration order.
599
- *
600
- * @typeParam Value - The TypeScript type of the parsed positional value.
820
+ * @typeParam Value - Decoded value type.
601
821
  */
602
822
  type Positional<Value> = {
603
- /** Returns human-readable metadata used to render the `Positionals:` section of help. */
604
- generateUsage(): PositionalUsage;
605
823
  /**
606
- * Consumes the positional from `readerPositionals` and then returns a parser that produces the final decoded value.
607
- *
608
- * The parser is created during {@link Operation.createFactory} and may throw a
609
- * {@link TypoError} if the positional is missing (when required) or if decoding fails.
610
- * @param readerPositionals - The source of positional arguments to be consumed.
824
+ * Returns metadata for the `Positionals:` section.
611
825
  */
612
- createParser(readerPositionals: ReaderPositionals): PositionalParser<Value>;
613
- };
614
- /**
615
- * Retrieves the parsed value for a positional argument after parsing is complete.
616
- *
617
- * Returned by {@link Positional.createParser} and called by {@link OperationFactory.createInstance}.
618
- *
619
- * @typeParam Value - The TypeScript type of the parsed value.
620
- */
621
- type PositionalParser<Value> = {
826
+ generateUsage(): UsagePositional;
622
827
  /**
623
- * Returns the fully decoded and validated value for the positional
624
- *
625
- * @throws {@link TypoError} if the positional was missing (when required) or if decoding failed.
828
+ * Consumes the next positional token from `readerPositionals`.
829
+ * Returns a decoder that produces the final value.
626
830
  */
627
- parseValue(): Value;
831
+ consumeAndMakeDecoder(readerPositionals: ReaderPositionals): PositionalDecoder<Value>;
628
832
  };
629
833
  /**
630
- * Human-readable metadata for a single positional argument, used to render the
631
- * `Positionals:` section of the help output produced by {@link usageToStyledLines}.
834
+ * Produced by {@link Positional.consumeAndMakeDecoder}.
835
+ *
836
+ * @typeParam Value - Decoded value type.
632
837
  */
633
- type PositionalUsage = {
634
- /** Short description of what the positional represents. */
635
- description: string | undefined;
838
+ type PositionalDecoder<Value> = {
636
839
  /**
637
- * Optional supplementary note shown in parentheses next to the description.
638
- * Suitable for short caveats such as `"defaults to 'world'"`.
639
- */
640
- hint: string | undefined;
641
- /**
642
- * The placeholder label shown in the usage line and the `Positionals:` section.
643
- * Required positionals use angle-bracket notation (e.g. `"<NAME>"`); optional ones
644
- * use square-bracket notation (e.g. `"[FILE]"`); variadic ones append `...`
645
- * (e.g. `"[ITEM]..."`).
840
+ * Returns the decoded positional value.
841
+ *
842
+ * @throws {@link TypoError} if decoding failed.
646
843
  */
647
- label: Uppercase<string>;
844
+ decodeValue(): Value;
648
845
  };
649
846
  /**
650
- * Creates a required positional argument one that must be present on the command line.
651
- *
652
- * The parser consumes the next available positional token and decodes it with
653
- * `definition.type`. If no token is available, a {@link TypoError} is thrown immediately
654
- * during parsing (i.e. inside {@link Operation.createFactory}).
847
+ * Creates a required positional — missing token throws {@link TypoError}.
848
+ * Label defaults to uppercased `type.content` in angle brackets (e.g. `<STRING>`).
655
849
  *
656
- * The label displayed in the usage line defaults to the uppercased `type.content`
657
- * wrapped in angle brackets (e.g. `<STRING>`). Supply `label` to override.
850
+ * @typeParam Value - Type produced by the decoder.
658
851
  *
659
- * @typeParam Value - The TypeScript type produced by the type decoder.
660
- *
661
- * @param definition - Configuration for the positional.
662
- * @param definition.description - Human-readable description for the help output.
663
- * @param definition.hint - Optional supplementary note shown in parentheses.
664
- * @param definition.label - Custom label shown in the usage line (without angle brackets).
665
- * Defaults to the uppercased `type.content`.
666
- * @param definition.type - The {@link Type} used to decode the raw string token.
852
+ * @param definition.description - Help text.
853
+ * @param definition.hint - Short note shown in parentheses.
854
+ * @param definition.label - Label without brackets; defaults to uppercased `type.content`.
855
+ * @param definition.type - Decoder for the raw token.
667
856
  * @returns A {@link Positional}`<Value>`.
668
857
  *
669
858
  * @example
@@ -683,26 +872,16 @@ declare function positionalRequired<Value>(definition: {
683
872
  type: Type<Value>;
684
873
  }): Positional<Value>;
685
874
  /**
686
- * Creates an optional positional argument one that may or may not appear on the
687
- * command line.
688
- *
689
- * The parser consumes the next available positional token. If no token is available,
690
- * `definition.default()` is called to supply the fallback value. If the default factory
691
- * throws, a {@link TypoError} is produced.
692
- *
693
- * The label displayed in the usage line defaults to the uppercased `type.content`
694
- * wrapped in square brackets (e.g. `[STRING]`). Supply `label` to override.
695
- *
696
- * @typeParam Value - The TypeScript type produced by the type decoder (or the default).
697
- *
698
- * @param definition - Configuration for the positional.
699
- * @param definition.description - Human-readable description for the help output.
700
- * @param definition.hint - Optional supplementary note shown in parentheses.
701
- * @param definition.label - Custom label shown in the usage line (without square brackets).
702
- * Defaults to the uppercased `type.content`.
703
- * @param definition.type - The {@link Type} used to decode the raw string token.
704
- * @param definition.default - Factory called when the positional is absent to supply the
705
- * default value. Throw from this factory to make omission an error.
875
+ * Creates an optional positional — absent token falls back to `default()`.
876
+ * Label defaults to uppercased `type.content` in square brackets (e.g. `[STRING]`).
877
+ *
878
+ * @typeParam Value - Type produced by the decoder (or the default).
879
+ *
880
+ * @param definition.description - Help text.
881
+ * @param definition.hint - Short note shown in parentheses.
882
+ * @param definition.label - Label without brackets; defaults to uppercased `type.content`.
883
+ * @param definition.type - Decoder for the raw token.
884
+ * @param definition.default - Value when absent. Throw to make it required.
706
885
  * @returns A {@link Positional}`<Value>`.
707
886
  *
708
887
  * @example
@@ -725,31 +904,16 @@ declare function positionalOptional<Value>(definition: {
725
904
  default: () => Value;
726
905
  }): Positional<Value>;
727
906
  /**
728
- * Creates a variadic positional argument — one that collects zero or more remaining
729
- * positional tokens into an array.
730
- *
731
- * The parser greedily consumes tokens until either there are no more tokens or it
732
- * encounters the optional `endDelimiter` sentinel string, which is consumed but not
733
- * included in the result. Each token is decoded independently with `definition.type`.
734
- *
735
- * If absent entirely, the result is an empty array `[]`.
736
- *
737
- * The label displayed in the usage line defaults to the uppercased `type.content`
738
- * wrapped in square brackets followed by `...` (e.g. `[STRING]...`). When an
739
- * `endDelimiter` is configured, the delimiter is also shown (e.g. `[STRING]...["--"]`).
740
- * Supply `label` to override the base label.
741
- *
742
- * @typeParam Value - The TypeScript type produced by the type decoder for each token.
743
- *
744
- * @param definition - Configuration for the variadic positional.
745
- * @param definition.endDelimiter - Optional sentinel string that signals the end of
746
- * the variadic sequence (e.g. `"--"`). When encountered it is consumed but not
747
- * included in the result array.
748
- * @param definition.description - Human-readable description for the help output.
749
- * @param definition.hint - Optional supplementary note shown in parentheses.
750
- * @param definition.label - Custom label shown in the usage line (without brackets).
751
- * Defaults to the uppercased `type.content`.
752
- * @param definition.type - The {@link Type} used to decode each raw string token.
907
+ * Creates a variadic positional that collects zero or more remaining tokens into an array.
908
+ * Stops at `endDelimiter` (consumed, not included). Label: `[TYPE]...` notation.
909
+ *
910
+ * @typeParam Value - Type produced by the decoder for each token.
911
+ *
912
+ * @param definition.endDelimiter - Sentinel token that stops collection (consumed, not included).
913
+ * @param definition.description - Help text.
914
+ * @param definition.hint - Short note shown in parentheses.
915
+ * @param definition.label - Label without brackets; defaults to uppercased `type.content`.
916
+ * @param definition.type - Decoder applied to each token.
753
917
  * @returns A {@link Positional}`<Array<Value>>`.
754
918
  *
755
919
  * @example
@@ -772,107 +936,65 @@ declare function positionalVariadics<Value>(definition: {
772
936
  }): Positional<Array<Value>>;
773
937
 
774
938
  /**
775
- * Describes an operation the combination of options, positional arguments, and an
776
- * async execution handler that together form the core logic of a CLI command.
777
- *
778
- * An `Operation` is created with {@link operation} and passed to
779
- * {@link command}, {@link commandWithSubcommands}, or {@link commandChained} to build
780
- * a full {@link Command}.
781
- *
782
- * @typeParam Input - The context value the handler receives at execution time (forwarded
783
- * from the parent command's context or from a preceding chained operation).
784
- * @typeParam Output - The value the handler produces. For leaf operations this is
785
- * typically `void`; for intermediate stages it is the payload forwarded to the next
786
- * command in a chain.
939
+ * Options, positionals, and an async handler that together form the logic of a CLI command.
940
+ *
941
+ * Created with {@link operation} and passed to {@link command},
942
+ * {@link commandWithSubcommands}, or {@link commandChained}.
943
+ *
944
+ * @typeParam Context - Injected at execution; forwarded to handlers.
945
+ * @typeParam Result - Value produced on execution; typically `void`.
787
946
  */
788
- type Operation<Input, Output> = {
947
+ type Operation<Context, Result> = {
789
948
  /**
790
- * Returns usage metadata (options and positionals) without consuming any arguments.
791
- * Called by the parent command factory when building the help/usage output.
949
+ * Returns usage metadata without consuming any arguments.
792
950
  */
793
- generateUsage(): OperationUsage;
951
+ generateUsage(): UsageOperation;
794
952
  /**
795
- * Parses options and positionals from `readerArgs` and returns an
796
- * {@link OperationFactory} that can create a ready-to-execute
797
- * {@link OperationInstance}.
798
- *
799
- * Any parse error (unknown option, type mismatch, etc.) is captured and re-thrown
800
- * when {@link OperationFactory.createInstance} is called.
801
- *
802
- * @param readerArgs - The shared argument reader. Options are registered on it and
803
- * positionals are consumed in declaration order.
953
+ * Consumes args from `readerArgs` and returns an {@link OperationDecoder}.
804
954
  */
805
- createFactory(readerArgs: ReaderArgs): OperationFactory<Input, Output>;
955
+ consumeAndMakeDecoder(readerArgs: ReaderArgs): OperationDecoder<Context, Result>;
806
956
  };
807
957
  /**
808
- * Produced by {@link Operation.createFactory} after argument parsing.
809
- * Instantiating it finalises value extraction and produces an {@link OperationInstance}.
958
+ * Produced by {@link Operation.consumeAndMakeDecoder}.
810
959
  *
811
- * @typeParam Input - operation instance input type {@link Operation}.
812
- * @typeParam Output - operation instance output type {@link Operation}.
960
+ * @typeParam Context - See {@link Operation}.
961
+ * @typeParam Result - See {@link Operation}.
813
962
  */
814
- type OperationFactory<Input, Output> = {
963
+ type OperationDecoder<Context, Result> = {
815
964
  /**
816
- * Extracts the final parsed values for all options and returns an
817
- * {@link OperationInstance} ready for execution.
965
+ * Creates a ready-to-execute {@link OperationInterpreter}.
818
966
  *
819
- * @throws {@link TypoError} if any option or positional validation failed during
820
- * {@link Operation.createFactory}.
967
+ * @throws {@link TypoError} if parsing or decoding failed.
821
968
  */
822
- createInstance(): OperationInstance<Input, Output>;
969
+ decodeAndMakeInterpreter(): OperationInterpreter<Context, Result>;
823
970
  };
824
971
  /**
825
- * A fully parsed, ready-to-execute operation.
972
+ * A fully parsed, decoded and ready-to-execute operation.
826
973
  *
827
- * @typeParam Input - The value the caller must supply as context.
828
- * @typeParam Output - The value produced on successful execution.
974
+ * @typeParam Context - Caller-supplied context.
975
+ * @typeParam Result - Value produced on success.
829
976
  */
830
- type OperationInstance<Input, Output> = {
977
+ type OperationInterpreter<Context, Result> = {
831
978
  /**
832
- * Runs the operation handler with the provided input context and the parsed
833
- * option/positional values.
834
- *
835
- * @param input - Context from the parent command (or the root context supplied to
836
- * {@link runAndExit}).
837
- * @returns A promise resolving to the handler's return value.
979
+ * Executes with the provided context.
838
980
  */
839
- executeWithContext(input: Input): Promise<Output>;
840
- };
841
- /**
842
- * Collected usage metadata produced by {@link Operation.generateUsage}.
843
- * Consumed by the parent command factory when building {@link CommandUsage}.
844
- */
845
- type OperationUsage = {
846
- /** Usage descriptors for all options registered by this operation. */
847
- options: Array<OptionUsage>;
848
- /** Usage descriptors for all positionals declared by this operation, in order. */
849
- positionals: Array<PositionalUsage>;
981
+ executeWithContext(context: Context): Promise<Result>;
850
982
  };
851
983
  /**
852
- * Creates an {@link Operation} from a set of options, positionals, and an
853
- * async handler function.
854
- *
855
- * The `handler` receives:
856
- * - `context` the value passed down from the parent command.
857
- * - `inputs.options` an object whose keys match those declared in `inputs.options` and whose values are
858
- * the parsed option values.
859
- * - `inputs.positionals` a tuple whose elements match `inputs.positionals` and whose
860
- * values are the parsed positional values, in declaration order.
861
- *
862
- * @typeParam Context - The context type accepted by the handler.
863
- * @typeParam Result - The return type of the handler.
864
- * @typeParam Options - Object type mapping option keys to their parsed value types.
865
- * @typeParam Positionals - Tuple type of parsed positional value types, in order.
866
- *
867
- * @param inputs - Declares the options and positionals this operation accepts.
868
- * @param inputs.options - A map from arbitrary keys to {@link Option} descriptors.
869
- * The same keys appear in `handler`'s `inputs.options` argument.
870
- * @param inputs.positionals - An ordered array of {@link Positional} descriptors.
871
- * Their parsed values appear in `handler`'s `inputs.positionals` argument, in the
872
- * same order.
873
- * @param handler - The async function that implements the command logic. Receives the
874
- * execution context and all parsed inputs.
875
- * @returns An {@link Operation} ready to be composed into a command.
984
+ * Creates an {@link Operation} from options, positionals, and an async handler.
985
+ *
986
+ * The `handler` receives `context` and `inputs` with decoded `options` and `positionals`.
987
+ *
988
+ * @typeParam Context - Context type accepted by the handler.
989
+ * @typeParam Result - Return type of the handler.
990
+ * @typeParam Options - Map of option keys to parsed value types.
991
+ * @typeParam Positionals - Tuple of parsed positional value types, in order.
992
+ *
993
+ * @param inputs - Options and positionals this operation accepts.
994
+ * @param inputs.options - Map of keys to {@link Option} descriptors.
995
+ * @param inputs.positionals - Ordered array of {@link Positional} descriptors.
996
+ * @param handler - Async function implementing the command logic.
997
+ * @returns An {@link Operation}.
876
998
  *
877
999
  * @example
878
1000
  * ```ts
@@ -885,7 +1007,7 @@ type OperationUsage = {
885
1007
  * positionalRequired({ type: typeString, label: "NAME", description: "Name to greet" }),
886
1008
  * ],
887
1009
  * },
888
- * async (_ctx, { options: { loud }, positionals: [name] }) => {
1010
+ * async function (_ctx, { options: { loud }, positionals: [name] }) {
889
1011
  * const message = `Hello, ${name}!`;
890
1012
  * console.log(loud ? message.toUpperCase() : message);
891
1013
  * },
@@ -907,168 +1029,102 @@ declare function operation<Context, Result, Options extends {
907
1029
  }) => Promise<Result>): Operation<Context, Result>;
908
1030
 
909
1031
  /**
910
- * Describes a CLI command: how to parse its arguments from raw CLI input and how to
911
- * execute it within a given context.
912
- *
913
- * A `Command` is the central building block of a `cli-kiss` CLI.
914
- * You create one with {@link command}, {@link commandWithSubcommands},
915
- * or {@link commandChained}, and pass it to {@link runAndExit} to run your CLI.
1032
+ * A CLI command. Created with {@link command}, {@link commandWithSubcommands}, or {@link commandChained}.
916
1033
  *
917
- * @typeParam Context - The value passed into the command when it is executed. It flows
918
- * from {@link runAndExit}'s `context` argument down through the command chain.
919
- * @typeParam Result - The value produced by executing the command. For root commands
920
- * passed to {@link runAndExit} this is always `void`.
1034
+ * @typeParam Context - Injected at execution; forwarded to handlers.
1035
+ * @typeParam Result - Produced on execution; typically `void`.
921
1036
  */
922
1037
  type Command<Context, Result> = {
923
1038
  /**
924
- * Returns the static metadata information about this command.
1039
+ * Returns static metadata.
925
1040
  */
926
1041
  getInformation(): CommandInformation;
927
1042
  /**
928
- * Parses `readerArgs` and returns a {@link CommandFactory} that can generate usage
929
- * information or create a ready-to-run {@link CommandInstance}.
930
- *
931
- * Parsing errors are captured and deferred: `createFactory` never throws; instead
932
- * the error surfaces when {@link CommandFactory.createInstance} is called on the
933
- * returned factory.
1043
+ * Registers options/positionals on `readerArgs`; returns a {@link CommandDecoder}.
934
1044
  */
935
- createFactory(readerArgs: ReaderArgs): CommandFactory<Context, Result>;
1045
+ consumeAndMakeDecoder(readerArgs: ReaderArgs): CommandDecoder<Context, Result>;
936
1046
  };
937
1047
  /**
938
- * Produced by {@link Command.createFactory} after the raw CLI arguments have
939
- * been parsed. Provides two capabilities:
940
- *
941
- * 1. **Usage generation** — always available, even when parsing failed.
942
- * 2. **Instance creation** — throws a {@link TypoError} if parsing failed.
1048
+ * Produced by {@link Command.consumeAndMakeDecoder}.
943
1049
  *
944
- * @typeParam Context - Input passed to the command {@link Command}.
945
- * @typeParam Result - Result of the command's logic {@link Command}.
1050
+ * @typeParam Context - See {@link Command}.
1051
+ * @typeParam Result - See {@link Command}.
946
1052
  */
947
- type CommandFactory<Context, Result> = {
1053
+ type CommandDecoder<Context, Result> = {
948
1054
  /**
949
- * Builds the complete {@link CommandUsage} for the currently parsed command path.
950
- * This is called to render the `--help` output and on error when `usageOnError`
951
- * is enabled.
1055
+ * Returns {@link UsageCommand} for the current command path.
952
1056
  */
953
- generateUsage(): CommandUsage;
1057
+ generateUsage(): UsageCommand;
954
1058
  /**
955
- * Creates a {@link CommandInstance} that is ready to execute.
1059
+ * Creates a ready-to-execute {@link CommandInterpreter}.
956
1060
  *
957
- * @throws {@link TypoError} if the argument parsing that occurred during
958
- * {@link Command.createFactory} encountered an error (e.g. unknown
959
- * option, missing required positional, invalid type).
1061
+ * @throws {@link TypoError} if parsing or decoding failed.
960
1062
  */
961
- createInstance(): CommandInstance<Context, Result>;
1063
+ decodeAndMakeInterpreter(): CommandInterpreter<Context, Result>;
962
1064
  };
963
1065
  /**
964
- * A fully parsed, ready-to-execute command.
1066
+ * A fully parsed, decoded and ready-to-execute command.
965
1067
  *
966
- * @typeParam Context - The value the caller must provide when executing the command.
967
- * @typeParam Result - The value the command produces on successful execution.
1068
+ * @typeParam Context - Context passed to the handler.
1069
+ * @typeParam Result - Value produced on success.
968
1070
  */
969
- type CommandInstance<Context, Result> = {
1071
+ type CommandInterpreter<Context, Result> = {
970
1072
  /**
971
- * Executes the command with the provided context.
972
- *
973
- * @param context - Arbitrary value injected by the caller (see {@link runAndExit}).
974
- * @returns A promise that resolves to the command's result, or rejects if the
975
- * command handler throws.
1073
+ * Executes with the provided context.
976
1074
  */
977
1075
  executeWithContext(context: Context): Promise<Result>;
978
1076
  };
979
1077
  /**
980
- * Static, human-readable metadata attached to a command.
981
- *
982
- * This information is displayed in the usage/help output produced by {@link usageToStyledLines}.
1078
+ * Command metadata shown in `--help` output.
983
1079
  */
984
1080
  type CommandInformation = {
985
- /** Short description of what the command does. Shown prominently in the usage header. */
1081
+ /**
1082
+ * Shown in the usage header.
1083
+ */
986
1084
  description: string;
987
1085
  /**
988
- * Optional supplementary note shown in parentheses next to the description.
989
- * Suitable for short caveats such as `"deprecated"` or `"experimental"`.
1086
+ * Shown in parentheses, e.g. `"deprecated"`, `"experimental"`.
990
1087
  */
991
1088
  hint?: string;
992
1089
  /**
993
- * Optional list of additional detail lines printed below the description.
994
- * Useful for multi-line explanations, examples, or caveats that don't fit in
995
- * a single sentence.
1090
+ * Extra lines printed below the description.
996
1091
  */
997
1092
  details?: Array<string>;
998
- };
999
- /**
1000
- * The full usage/help model for a command as it appears after argument parsing.
1001
- *
1002
- * This is produced by {@link CommandFactory.generateUsage} and consumed by
1003
- * {@link usageToStyledLines} to render the `--help` output.
1004
- */
1005
- type CommandUsage = {
1006
- /**
1007
- * Ordered list of breadcrumb segments that form the command's usage line, e.g.:
1008
- * `Usage: my-cli <POSITIONAL> subcommand <ANOTHER_POSITIONAL>`.
1009
- *
1010
- * Each element is either a positional placeholder or a literal subcommand name.
1011
- */
1012
- breadcrumbs: Array<CommandUsageBreadcrumb>;
1013
- /** The command's static metadata (description, hint, details). */
1014
- information: CommandInformation;
1015
- /**
1016
- * Positional arguments that belong to the current command path,
1017
- * in the order they must appear on the command line.
1018
- */
1019
- positionals: Array<PositionalUsage>;
1020
1093
  /**
1021
- * Subcommands available at the current level of the command hierarchy.
1022
- * Non-empty only when the command is a {@link commandWithSubcommands} and the
1023
- * subcommand selection could not be resolved (i.e. on error or `--help`).
1094
+ * Shown in the `Examples:` section.
1024
1095
  */
1025
- subcommands: Array<CommandUsageSubcommand>;
1026
- /**
1027
- * Options (flags and valued options) accepted by the current command path,
1028
- * in the order they were registered.
1029
- */
1030
- options: Array<OptionUsage>;
1031
- };
1032
- /**
1033
- * A single element in the usage breadcrumb trail shown at the top of the help output.
1034
- *
1035
- * - `{ positional: string }` — A positional placeholder such as `<NAME>` or `[FILE]`.
1036
- * - `{ command: string }` — A literal subcommand token such as `deploy`.
1037
- */
1038
- type CommandUsageBreadcrumb = {
1039
- positional: string;
1040
- } | {
1041
- command: string;
1096
+ examples?: Array<{
1097
+ /**
1098
+ * Explanation shown above the example.
1099
+ */
1100
+ explanation: string;
1101
+ /**
1102
+ * Example command args.
1103
+ */
1104
+ commandArgs: Array<string | {
1105
+ positional: string;
1106
+ } | {
1107
+ subcommand: string;
1108
+ } | {
1109
+ option: {
1110
+ long: string;
1111
+ value?: string;
1112
+ } | {
1113
+ short: string;
1114
+ value?: string;
1115
+ };
1116
+ }>;
1117
+ }>;
1042
1118
  };
1043
1119
  /**
1044
- * Summary information about a single subcommand shown in the `Subcommands:` section
1045
- * of the usage output.
1046
- */
1047
- type CommandUsageSubcommand = {
1048
- /** The literal token the user types to select this subcommand (e.g. `"deploy"`). */
1049
- name: string;
1050
- /** Short description forwarded from the subcommand's {@link CommandInformation}. */
1051
- description: string | undefined;
1052
- /** Optional hint forwarded from the subcommand's {@link CommandInformation}. */
1053
- hint: string | undefined;
1054
- };
1055
- /**
1056
- * Creates a leaf command — a command that has no subcommands and directly executes
1057
- * an {@link Operation}.
1120
+ * Creates a leaf command that directly executes an {@link Operation}.
1058
1121
  *
1059
- * During parsing, `command` reads all positionals and options consumed by `operation`,
1060
- * then asserts that no extra positionals remain. Any unexpected trailing positional
1061
- * causes a {@link TypoError} deferred to {@link CommandFactory.createInstance}.
1122
+ * @typeParam Context - Context forwarded to the handler.
1123
+ * @typeParam Result - Value returned by the handler.
1062
1124
  *
1063
- * @typeParam Context - The context value forwarded to the operation handler at
1064
- * execution time.
1065
- * @typeParam Result - The value returned by the operation handler.
1066
- *
1067
- * @param information - Static metadata (description, hint, details) for the command.
1068
- * @param operation - The operation that defines options, positionals, and the execution
1069
- * handler for this command.
1070
- * @returns A {@link Command} suitable for passing to {@link runAndExit}
1071
- * or composing with {@link commandWithSubcommands} / {@link commandChained}.
1125
+ * @param information - Command metadata.
1126
+ * @param operation - Options, positionals, and handler.
1127
+ * @returns A {@link Command}.
1072
1128
  *
1073
1129
  * @example
1074
1130
  * ```ts
@@ -1083,34 +1139,16 @@ type CommandUsageSubcommand = {
1083
1139
  */
1084
1140
  declare function command<Context, Result>(information: CommandInformation, operation: Operation<Context, Result>): Command<Context, Result>;
1085
1141
  /**
1086
- * Creates a command that first runs an {@link Operation} to produce an
1087
- * intermediate `Payload`, then dispatches execution to one of several named subcommands
1088
- * based on the next positional argument.
1089
- *
1090
- * **Parsing behaviour:**
1091
- * 1. The `operation`'s positionals and options are parsed from `readerArgs`.
1092
- * 2. The next positional token is consumed as the subcommand name.
1093
- * - If no token is present, a {@link TypoError} is deferred.
1094
- * - If the token does not match any key in `subcommands`, a {@link TypoError} is
1095
- * deferred.
1096
- * 3. The matched subcommand's factory is created with the remaining `readerArgs`.
1097
- *
1098
- * **Usage on error / `--help`:** when the subcommand cannot be determined, the usage
1099
- * output lists all available subcommands under a `Subcommands:` section.
1100
- *
1101
- * @typeParam Context - The context value accepted by the root operation handler.
1102
- * @typeParam Payload - The value produced by the root operation and forwarded as the
1103
- * context to the selected subcommand.
1104
- * @typeParam Result - The value produced by the selected subcommand.
1105
- *
1106
- * @param information - Static metadata shown in the top-level usage when no valid
1107
- * subcommand has been selected.
1108
- * @param operation - The operation that is always executed first, before the
1109
- * subcommand. Its output becomes the subcommand's context.
1110
- * @param subcommands - A map of lowercase subcommand names to their
1111
- * {@link Command}s. The keys are the literal tokens the user types.
1112
- * @returns A {@link Command} that dispatches to one of the provided
1113
- * subcommands.
1142
+ * Creates a command that runs `operation` first, then dispatches to a named subcommand.
1143
+ *
1144
+ * @typeParam Context - Context accepted by `operation`.
1145
+ * @typeParam Payload - Output of `operation`; becomes the subcommand's context.
1146
+ * @typeParam Result - Value produced by the selected subcommand.
1147
+ *
1148
+ * @param information - Command metadata.
1149
+ * @param operation - Runs first; output becomes the subcommand's context.
1150
+ * @param subcommands - Map of subcommand names to their {@link Command}s.
1151
+ * @returns A dispatching {@link Command}.
1114
1152
  *
1115
1153
  * @example
1116
1154
  * ```ts
@@ -1128,36 +1166,17 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
1128
1166
  [subcommand: Lowercase<string>]: Command<Payload, Result>;
1129
1167
  }): Command<Context, Result>;
1130
1168
  /**
1131
- * Creates a command that chains two command stages by piping the output of an
1132
- * {@link Operation} directly into a {@link Command} as its context.
1133
- *
1134
- * Unlike {@link commandWithSubcommands}, there is no runtime token consumed for routing;
1135
- * the `nextCommand` is always the continuation. This is useful for splitting a complex
1136
- * command into reusable pieces, such as a shared authentication step followed by
1137
- * different sub-actions.
1138
- *
1139
- * **Parsing behaviour:**
1140
- * 1. `operation`'s positionals and options are parsed.
1141
- * 2. `nextCommand`'s factory is immediately created from the same `readerArgs` (the
1142
- * remaining unparsed tokens).
1143
- * 3. At execution time, `operation` runs first; its result is passed as the context to
1144
- * `nextCommand`.
1145
- *
1146
- * **Usage:** breadcrumbs, positionals, and options from both stages are merged into a
1147
- * single flat usage description. The `information` of `nextCommand` takes precedence in
1148
- * the generated usage output.
1149
- *
1150
- * @typeParam Context - The context value accepted by `operation`.
1151
- * @typeParam Payload - The value produced by `operation` and used as the context for
1152
- * `nextCommand`.
1153
- * @typeParam Result - The value produced by `nextCommand`.
1154
- *
1155
- * @param information - Fallback metadata used in the usage output when `nextCommand`'s
1156
- * factory cannot be created (i.e. on parse error in the next stage).
1157
- * @param operation - The first stage operation. Its output becomes `nextCommand`'s
1158
- * context.
1159
- * @param nextCommand - The second stage command, executed after `operation` succeeds.
1160
- * @returns A {@link Command} that transparently composes the two stages.
1169
+ * Chains an {@link Operation} and a {@link Command}: `operation` runs first, its
1170
+ * output becomes `subcommand`'s context. No token is consumed for routing.
1171
+ *
1172
+ * @typeParam Context - Context accepted by `operation`.
1173
+ * @typeParam Payload - Output of `operation`; becomes `subcommand`'s context.
1174
+ * @typeParam Result - Value produced by `subcommand`.
1175
+ *
1176
+ * @param information - Command metadata.
1177
+ * @param operation - Runs first; output becomes `subcommand`'s context.
1178
+ * @param subcommand - Runs after `operation`.
1179
+ * @returns A {@link Command} composing both stages.
1161
1180
  *
1162
1181
  * @example
1163
1182
  * ```ts
@@ -1171,56 +1190,31 @@ declare function commandWithSubcommands<Context, Payload, Result>(information: C
1171
1190
  * );
1172
1191
  * ```
1173
1192
  */
1174
- declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, nextCommand: Command<Payload, Result>): Command<Context, Result>;
1193
+ declare function commandChained<Context, Payload, Result>(information: CommandInformation, operation: Operation<Context, Payload>, subcommand: Command<Payload, Result>): Command<Context, Result>;
1175
1194
 
1176
1195
  /**
1177
- * Parses the provided CLI arguments against the given command descriptor, executes
1178
- * the matched command, and exits the process with an appropriate exit code.
1179
- *
1180
- * This is the primary entry point for running a `cli-kiss`-based CLI application.
1181
- * It handles argument parsing, `--help` / `--version` flags, usage printing on errors,
1182
- * and exit code management.
1183
- *
1184
- * **Exit codes:**
1185
- * - `0` — Command executed successfully, or `--help` / `--version` was handled.
1186
- * - `1` Argument parsing failed (a usage summary is also printed to stderr), or the
1187
- * command threw an unhandled execution error.
1188
- *
1189
- * **Built-in flags:**
1190
- * - `--help` Enabled by default (`usageOnHelp: true`). Prints the usage summary to
1191
- * stdout and exits with code `0`. This flag takes precedence over `--version`.
1192
- * - `--version` Enabled when `buildVersion` is provided. Prints `<cliName> <version>`
1193
- * to stdout and exits with code `0`.
1194
- *
1195
- * @typeParam Context - Arbitrary value passed unchanged to the command's execution handler.
1196
- * Use this to inject dependencies (e.g. a database connection, a logger) into your commands.
1197
- *
1198
- * @param cliName - The name of the CLI program (e.g. `"my-cli"`). Used in the usage
1199
- * summary header and in the `--version` output.
1200
- * @param cliArgs - The raw command-line arguments to parse, typically `process.argv.slice(2)`.
1201
- * @param context - The context value forwarded to the command's execution handler.
1202
- * @param command - The root {@link Command} that describes how to parse and execute
1203
- * the CLI.
1204
- * @param options - Optional configuration for the runner.
1205
- * @param options.useTtyColors - Controls terminal color output in styled messages.
1206
- * - `true` — Always apply ANSI color codes.
1207
- * - `false` — Never apply color codes (plain text).
1208
- * - `"mock"` — Use a deterministic mock style useful for snapshot testing.
1209
- * - `undefined` (default) — Auto-detect based on `process.stdout.isTTY` and the
1210
- * `FORCE_COLOR` / `NO_COLOR` environment variables.
1211
- * @param options.usageOnHelp - When `true` (default), registers a `--help` flag that
1212
- * prints the usage summary and exits with code `0`.
1213
- * @param options.usageOnError - When `true` (default), prints the usage summary to
1214
- * stderr before the error message whenever argument parsing fails.
1215
- * @param options.buildVersion - When provided, registers a `--version` flag that prints
1216
- * `<cliName> <buildVersion>` to stdout and exits with code `0`.
1217
- * @param options.onError - Custom handler for errors thrown during command execution.
1218
- * If omitted, the error is printed to stderr via {@link TypoSupport}.
1219
- * @param options.onExit - Overrides the process exit function (default: `process.exit`).
1220
- * Useful for testing — supply a function that throws or captures the exit code instead
1221
- * of actually terminating the process.
1222
- *
1223
- * @returns A `Promise<never>` because the function always terminates by calling `onExit`.
1196
+ * Main entry point: parses CLI arguments, executes the matched command, and exits.
1197
+ * Handles `--help`, `--version`, usage-on-error, and exit codes.
1198
+ *
1199
+ * Exit codes:
1200
+ * - `0` on success / `--help` / `--version`
1201
+ * - `1` on parse error or execution error.
1202
+ *
1203
+ * @typeParam Context - Forwarded unchanged to the handler.
1204
+ *
1205
+ * @param cliName - Program name used in usage and `--version` output.
1206
+ * @param cliArgs - Raw arguments, typically `process.argv.slice(2)`.
1207
+ * @param context - Forwarded to the handler.
1208
+ * @param command - Root {@link Command}.
1209
+ * @param options.useTtyColors - Color mode: `true` (always), `false` (never),
1210
+ * `"mock"` (snapshot-friendly), `undefined` (auto-detect from env).
1211
+ * @param options.usageOnHelp - Enables `--help` flag (default `true`).
1212
+ * @param options.usageOnError - Prints usage to stderr on parse error (default `true`).
1213
+ * @param options.buildVersion - Enables `--version`; prints `<cliName> <buildVersion>`.
1214
+ * @param options.onError - Custom handler for errors.
1215
+ * @param options.onExit - Overrides `process.exit`; useful for testing.
1216
+ *
1217
+ * @returns `Promise<never>` always calls `onExit`.
1224
1218
  *
1225
1219
  * @example
1226
1220
  * ```ts
@@ -1230,7 +1224,7 @@ declare function commandChained<Context, Payload, Result>(information: CommandIn
1230
1224
  * { description: "Greet someone" },
1231
1225
  * operation(
1232
1226
  * { options: {}, positionals: [positionalRequired({ type: typeString, label: "NAME" })] },
1233
- * async (_ctx, { positionals: [name] }) => {
1227
+ * async function (_ctx, { positionals: [name] }) {
1234
1228
  * console.log(`Hello, ${name}!`);
1235
1229
  * },
1236
1230
  * ),
@@ -1250,333 +1244,4 @@ declare function runAndExit<Context>(cliName: Lowercase<string>, cliArgs: Readon
1250
1244
  onExit?: ((code: number) => never) | undefined;
1251
1245
  }): Promise<never>;
1252
1246
 
1253
- /**
1254
- * Available foreground and background color names for terminal styling.
1255
- *
1256
- * Colors are divided into two groups:
1257
- * - **dark** variants correspond to standard ANSI colors (codes 30–37 / 40–47).
1258
- * - **bright** variants correspond to high-intensity ANSI colors (codes 90–97 / 100–107).
1259
- *
1260
- * Used by {@link TypoStyle}'s `fgColor` and `bgColor` fields.
1261
- */
1262
- type TypoColor = "darkBlack" | "darkRed" | "darkGreen" | "darkYellow" | "darkBlue" | "darkMagenta" | "darkCyan" | "darkWhite" | "brightBlack" | "brightRed" | "brightGreen" | "brightYellow" | "brightBlue" | "brightMagenta" | "brightCyan" | "brightWhite";
1263
- /**
1264
- * Describes the visual styling to apply to a text segment when rendered by a
1265
- * {@link TypoSupport} instance.
1266
- *
1267
- * All fields are optional. When `TypoSupport` is in `"none"` mode, no styling is
1268
- * applied and the raw text is returned unchanged. In `"tty"` mode the corresponding
1269
- * ANSI escape codes are emitted. In `"mock"` mode a deterministic textual representation
1270
- * is produced (useful for snapshot tests).
1271
- */
1272
- type TypoStyle = {
1273
- /** Foreground (text) color. */
1274
- fgColor?: TypoColor;
1275
- /** Background color. */
1276
- bgColor?: TypoColor;
1277
- /** Render the text with reduced intensity. */
1278
- dim?: boolean;
1279
- /** Render the text in bold. */
1280
- bold?: boolean;
1281
- /** Render the text in italic. */
1282
- italic?: boolean;
1283
- /** Render the text with an underline. */
1284
- underline?: boolean;
1285
- /** Render the text with a strikethrough. */
1286
- strikethrough?: boolean;
1287
- };
1288
- /**
1289
- * Pre-defined {@link TypoStyle} for section titles in the usage output (e.g.
1290
- * `"Positionals:"`, `"Options:"`).
1291
- * Rendered in bold dark-green.
1292
- */
1293
- declare const typoStyleTitle: TypoStyle;
1294
- /** Pre-defined {@link TypoStyle} for logic/type identifiers in error messages. Rendered in bold dark-magenta. */
1295
- declare const typoStyleLogic: TypoStyle;
1296
- /** Pre-defined {@link TypoStyle} for quoted user-supplied values in error messages. Rendered in bold dark-yellow. */
1297
- declare const typoStyleQuote: TypoStyle;
1298
- /** Pre-defined {@link TypoStyle} for failure/error labels (e.g. `"Error:"`). Rendered in bold dark-red. */
1299
- declare const typoStyleFailure: TypoStyle;
1300
- /** Pre-defined {@link TypoStyle} for CLI flag/option/command constant names. Rendered in bold dark-cyan. */
1301
- declare const typoStyleConstants: TypoStyle;
1302
- /** Pre-defined {@link TypoStyle} for positional placeholders and user-input labels. Rendered in bold dark-blue. */
1303
- declare const typoStyleUserInput: TypoStyle;
1304
- /** Pre-defined {@link TypoStyle} for strong regular text (e.g. command descriptions). Rendered in bold. */
1305
- declare const typoStyleRegularStrong: TypoStyle;
1306
- /** Pre-defined {@link TypoStyle} for subtle supplementary text (e.g. hints). Rendered in italic and dim. */
1307
- declare const typoStyleRegularWeaker: TypoStyle;
1308
- /**
1309
- * An immutable styled string segment consisting of a raw text value and an associated
1310
- * {@link TypoStyle}.
1311
- *
1312
- * Multiple `TypoString`s are composed into a {@link TypoText} for multi-part messages.
1313
- * Rendering is deferred until {@link TypoString.computeStyledString} is called with a
1314
- * {@link TypoSupport} instance.
1315
- */
1316
- declare class TypoString {
1317
- #private;
1318
- /**
1319
- * @param value - The raw text content.
1320
- * @param typoStyle - The style to apply when rendering. Defaults to `{}` (no style).
1321
- */
1322
- constructor(value: string, typoStyle?: TypoStyle);
1323
- /** Returns the unstyled raw text content. */
1324
- getRawString(): string;
1325
- /**
1326
- * Returns the text with ANSI escape codes (or mock markers) applied by `typoSupport`.
1327
- *
1328
- * @param typoSupport - Controls how styles are rendered (tty colors, mock, or none).
1329
- */
1330
- computeStyledString(typoSupport: TypoSupport): string;
1331
- }
1332
- /**
1333
- * A mutable sequence of {@link TypoString} segments that together form a styled
1334
- * multi-part message.
1335
- *
1336
- * `TypoText` is used throughout the library to build error messages and usage output
1337
- * that carry styling information without being coupled to a specific output mode.
1338
- * Rendering is deferred to {@link TypoText.computeStyledString}.
1339
- */
1340
- declare class TypoText {
1341
- #private;
1342
- /**
1343
- * Creates a `TypoText` pre-populated with the provided parts. Each part can be a
1344
- * `TypoText` (flattened by value), a `TypoString`, or a plain `string` (wrapped in an
1345
- * unstyled `TypoString`).
1346
- *
1347
- * @param typoParts - Initial parts to append. Can be any mix of `TypoText`,
1348
- * `TypoString`, and `string`.
1349
- */
1350
- constructor(...typoParts: Array<TypoText | TypoString | string>);
1351
- /**
1352
- * Appends a single {@link TypoString} segment to the end of this text.
1353
- *
1354
- * @param typoString - The segment to append.
1355
- */
1356
- pushString(typoString: TypoString): void;
1357
- /**
1358
- * Appends all segments from another {@link TypoText} to the end of this text
1359
- * (shallow copy of segments).
1360
- *
1361
- * @param typoText - The text whose segments are appended.
1362
- */
1363
- pushText(typoText: TypoText): void;
1364
- /**
1365
- * Renders all segments into a single string, applying styles via `typoSupport`.
1366
- *
1367
- * @param typoSupport - Controls how styles are rendered.
1368
- * @returns The concatenated, optionally styled string.
1369
- */
1370
- computeStyledString(typoSupport: TypoSupport): string;
1371
- /**
1372
- * Returns the concatenation of all segments' raw (unstyled) text.
1373
- * Equivalent to calling {@link TypoText.computeStyledString} with
1374
- * {@link TypoSupport.none}.
1375
- */
1376
- computeRawString(): string;
1377
- /**
1378
- * Returns the total character length of the raw (unstyled) text.
1379
- * Used by {@link TypoGrid} to compute column widths for alignment.
1380
- */
1381
- computeRawLength(): number;
1382
- }
1383
- /**
1384
- * A grid of {@link TypoText} cells that renders with column-aligned padding.
1385
- *
1386
- * Each row is an array of `TypoText` cells. When {@link TypoGrid.computeStyledGrid} is
1387
- * called, each column is padded to the width of its widest cell (measured in raw
1388
- * characters). The last column in each row is **not** padded.
1389
- *
1390
- * Used internally by {@link usageToStyledLines} to render the `Positionals:`,
1391
- * `Subcommands:`, and `Options:` sections with neat alignment.
1392
- */
1393
- declare class TypoGrid {
1394
- #private;
1395
- constructor();
1396
- /**
1397
- * Appends a row of cells to the grid.
1398
- *
1399
- * @param cells - An ordered array of {@link TypoText} cells for this row. All rows
1400
- * should have the same number of cells for alignment to be meaningful.
1401
- */
1402
- pushRow(cells: Array<TypoText>): void;
1403
- /**
1404
- * Renders the grid into a 2-D array of styled strings, with space padding added
1405
- * between columns (except after the last column).
1406
- *
1407
- * @param typoSupport - Controls how styles are rendered.
1408
- * @returns A 2-D array where each inner array is the styled (and padded) cells of
1409
- * one row. Join the inner arrays with `""` to get a single line string.
1410
- */
1411
- computeStyledGrid(typoSupport: TypoSupport): Array<Array<string>>;
1412
- }
1413
- /**
1414
- * An `Error` subclass that carries a {@link TypoText} styled message in addition to
1415
- * the plain-text `Error.message` used by the standard JS error chain.
1416
- *
1417
- * `TypoError` is used throughout `cli-kiss` to report parsing failures (unknown option,
1418
- * type decoding error, missing required argument, etc.). Its styled representation is
1419
- * rendered by {@link TypoSupport.computeStyledErrorMessage} when outputting errors to
1420
- * the terminal.
1421
- *
1422
- * Errors can be chained: if `source` is a `TypoError`, its styled text is appended
1423
- * after `": "` to form the full message context chain.
1424
- */
1425
- declare class TypoError extends Error {
1426
- #private;
1427
- /**
1428
- * @param currentTypoText - The styled message for this error level.
1429
- * @param source - An optional cause. If it is a `TypoError`, its styled text is
1430
- * appended (chained context). If it is a plain `Error`, its `.message` is appended
1431
- * as a plain string. Any other value is stringified with `String()`.
1432
- */
1433
- constructor(currentTypoText: TypoText, source?: unknown);
1434
- /**
1435
- * Renders this error's styled message as a string.
1436
- *
1437
- * @param typoSupport - Controls how ANSI styles are applied.
1438
- * @returns The full styled error message (without a leading `"Error:"` prefix).
1439
- */
1440
- computeStyledString(typoSupport: TypoSupport): string;
1441
- /**
1442
- * Executes `thrower` and returns its result. If `thrower` throws any error, the error
1443
- * is re-thrown as a new `TypoError` whose message is `context()` with the original
1444
- * error chained as the source.
1445
- *
1446
- * This is a convenience helper for adding contextual information to errors that arise
1447
- * deep in a call chain (e.g. "at 0: Number: Unable to parse: ...").
1448
- *
1449
- * @typeParam Value - The return type of `thrower`.
1450
- * @param thrower - A zero-argument function whose return value is passed through on
1451
- * success.
1452
- * @param context - A zero-argument factory that produces the {@link TypoText} context
1453
- * prepended to the caught error. Called only when `thrower` throws.
1454
- * @returns The value returned by `thrower`.
1455
- * @throws `TypoError` wrapping the original error with the provided context prepended.
1456
- */
1457
- static tryWithContext<Value>(thrower: () => Value, context: () => TypoText): Value;
1458
- }
1459
- /**
1460
- * Controls whether and how ANSI terminal styling is applied when rendering
1461
- * {@link TypoString}, {@link TypoText}, and error messages.
1462
- *
1463
- * Instances are created via the static factory methods:
1464
- * - {@link TypoSupport.none} — strips all styling (plain text).
1465
- * - {@link TypoSupport.tty} — applies ANSI escape codes for color terminals.
1466
- * - {@link TypoSupport.mock} — applies a deterministic textual representation useful
1467
- * for snapshot tests.
1468
- * - {@link TypoSupport.inferFromProcess} — auto-detects based on `process.stdout.isTTY`
1469
- * and the `FORCE_COLOR` / `NO_COLOR` environment variables.
1470
- *
1471
- * `TypoSupport` is consumed by {@link runAndExit} (via the `useTtyColors` option)
1472
- * and can also be used directly when building custom usage renderers with {@link usageToStyledLines}.
1473
- */
1474
- declare class TypoSupport {
1475
- #private;
1476
- private constructor();
1477
- /**
1478
- * Returns a `TypoSupport` that strips all styling — every styled string is returned
1479
- * as-is (plain text, no ANSI codes).
1480
- */
1481
- static none(): TypoSupport;
1482
- /**
1483
- * Returns a `TypoSupport` that applies ANSI escape codes.
1484
- * Use this when writing to a color-capable terminal (`stdout.isTTY === true`).
1485
- */
1486
- static tty(): TypoSupport;
1487
- /**
1488
- * Returns a `TypoSupport` that applies a deterministic mock styling representation.
1489
- *
1490
- * Instead of real ANSI codes, each style flag is expressed as a readable suffix:
1491
- * `{text}@color`, `{text}+` (bold), `{text}-` (dim), `{text}*` (italic),
1492
- * `{text}_` (underline), `{text}~` (strikethrough). Useful for snapshot testing.
1493
- */
1494
- static mock(): TypoSupport;
1495
- /**
1496
- * Selects a `TypoSupport` mode automatically based on the current process environment:
1497
- *
1498
- * 1. `FORCE_COLOR=0` or `NO_COLOR` env var set → {@link TypoSupport.none}.
1499
- * 2. `FORCE_COLOR` env var set (any truthy value) → {@link TypoSupport.tty}.
1500
- * 3. `process.stdout.isTTY === true` → {@link TypoSupport.tty}.
1501
- * 4. Otherwise → {@link TypoSupport.none}.
1502
- *
1503
- * Falls back to {@link TypoSupport.none} if `process` is not available (e.g. in a
1504
- * non-Node environment).
1505
- */
1506
- static inferFromProcess(): TypoSupport;
1507
- /**
1508
- * Applies the given {@link TypoStyle} to `value` and returns the styled string.
1509
- *
1510
- * - In `"none"` mode: returns `value` unchanged.
1511
- * - In `"tty"` mode: wraps `value` in ANSI escape codes and appends a reset code.
1512
- * - In `"mock"` mode: wraps `value` in a deterministic textual representation.
1513
- *
1514
- * @param value - The raw text to style.
1515
- * @param typoStyle - The style to apply.
1516
- * @returns The styled string.
1517
- */
1518
- computeStyledString(value: string, typoStyle: TypoStyle): string;
1519
- /**
1520
- * Formats an error value as a styled `"Error: <message>"` string.
1521
- *
1522
- * - If `error` is a {@link TypoError}, its styled text is used for the message part.
1523
- * - If `error` is a plain `Error`, its `.message` property is used.
1524
- * - Otherwise `String(error)` is used.
1525
- *
1526
- * The `"Error:"` prefix is always styled with {@link typoStyleFailure}.
1527
- *
1528
- * @param error - The error to format (any value thrown by a handler).
1529
- * @returns A styled error string ready to print to stderr.
1530
- */
1531
- computeStyledErrorMessage(error: unknown): string;
1532
- }
1533
-
1534
- /**
1535
- * Converts a {@link CommandUsage} model into an array of styled lines ready to be
1536
- * joined with `"\n"` and printed to the terminal.
1537
- *
1538
- * The output format is:
1539
- * ```
1540
- * Usage: <cliName> [breadcrumbs...]
1541
- *
1542
- * <description> (<hint>)
1543
- * <detail lines...>
1544
- *
1545
- * Positionals:
1546
- * <LABEL> <description> (<hint>)
1547
- *
1548
- * Subcommands:
1549
- * <name> <description> (<hint>)
1550
- *
1551
- * Options:
1552
- * -s, --long <LABEL> <description> (<hint>)
1553
- *
1554
- * ```
1555
- * Sections that have no entries are omitted. The trailing empty line is always included.
1556
- *
1557
- * Column alignment within each section is handled by {@link TypoGrid}: the widest entry
1558
- * in each column sets the width for the entire section.
1559
- *
1560
- * @param params.cliName - The CLI program name shown at the start of the usage line.
1561
- * @param params.commandUsage - The usage model produced by {@link CommandFactory.generateUsage}.
1562
- * @param params.typoSupport - Controls color/styling of the output.
1563
- * @returns An ordered array of strings, one per output line (including a trailing
1564
- * empty string for the blank line at the end).
1565
- *
1566
- * @example
1567
- * ```ts
1568
- * const lines = usageToStyledLines({
1569
- * cliName: "my-cli",
1570
- * commandUsage: commandFactory.generateUsage(),
1571
- * typoSupport: TypoSupport.tty(),
1572
- * });
1573
- * process.stdout.write(lines.join("\n"));
1574
- * ```
1575
- */
1576
- declare function usageToStyledLines(params: {
1577
- cliName: Lowercase<string>;
1578
- commandUsage: CommandUsage;
1579
- typoSupport: TypoSupport;
1580
- }): string[];
1581
-
1582
- export { type Command, type CommandFactory, type CommandInformation, type CommandInstance, type CommandUsage, type CommandUsageBreadcrumb, type CommandUsageSubcommand, type Operation, type OperationFactory, type OperationInstance, type OperationUsage, type Option, type OptionParser, type OptionUsage, type Positional, type PositionalParser, 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, typeConverted, typeDate, typeInteger, typeList, typeNumber, typeOneOf, typeString, typeTuple, typeUrl, typoStyleConstants, typoStyleFailure, typoStyleLogic, typoStyleQuote, typoStyleRegularStrong, typoStyleRegularWeaker, typoStyleTitle, typoStyleUserInput, usageToStyledLines };
1247
+ 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 UsageOperation, type UsageOption, type UsagePositional, type UsageSegment, type UsageSubcommand, 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 };