@optique/core 1.0.0-dev.908 → 1.0.0

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.
Files changed (109) hide show
  1. package/dist/annotation-state.cjs +425 -0
  2. package/dist/annotation-state.d.cts +24 -0
  3. package/dist/annotation-state.d.ts +24 -0
  4. package/dist/annotation-state.js +414 -0
  5. package/dist/annotations.cjs +2 -248
  6. package/dist/annotations.d.cts +2 -137
  7. package/dist/annotations.d.ts +2 -137
  8. package/dist/annotations.js +2 -238
  9. package/dist/completion.cjs +611 -100
  10. package/dist/completion.d.cts +1 -1
  11. package/dist/completion.d.ts +1 -1
  12. package/dist/completion.js +611 -100
  13. package/dist/constructs.cjs +3338 -827
  14. package/dist/constructs.d.cts +48 -7
  15. package/dist/constructs.d.ts +48 -7
  16. package/dist/constructs.js +3338 -827
  17. package/dist/context.cjs +0 -23
  18. package/dist/context.d.cts +119 -53
  19. package/dist/context.d.ts +119 -53
  20. package/dist/context.js +0 -22
  21. package/dist/dependency-metadata.cjs +139 -0
  22. package/dist/dependency-metadata.d.cts +112 -0
  23. package/dist/dependency-metadata.d.ts +112 -0
  24. package/dist/dependency-metadata.js +138 -0
  25. package/dist/dependency-runtime.cjs +698 -0
  26. package/dist/dependency-runtime.d.cts +149 -0
  27. package/dist/dependency-runtime.d.ts +149 -0
  28. package/dist/dependency-runtime.js +687 -0
  29. package/dist/dependency.cjs +7 -928
  30. package/dist/dependency.d.cts +2 -794
  31. package/dist/dependency.d.ts +2 -794
  32. package/dist/dependency.js +2 -899
  33. package/dist/displaywidth.cjs +44 -0
  34. package/dist/displaywidth.js +43 -0
  35. package/dist/doc.cjs +285 -23
  36. package/dist/doc.d.cts +57 -2
  37. package/dist/doc.d.ts +57 -2
  38. package/dist/doc.js +283 -25
  39. package/dist/execution-context.cjs +56 -0
  40. package/dist/execution-context.js +53 -0
  41. package/dist/extension.cjs +87 -0
  42. package/dist/extension.d.cts +97 -0
  43. package/dist/extension.d.ts +97 -0
  44. package/dist/extension.js +76 -0
  45. package/dist/facade.cjs +718 -523
  46. package/dist/facade.d.cts +87 -18
  47. package/dist/facade.d.ts +87 -18
  48. package/dist/facade.js +718 -523
  49. package/dist/index.cjs +14 -29
  50. package/dist/index.d.cts +10 -10
  51. package/dist/index.d.ts +10 -10
  52. package/dist/index.js +7 -7
  53. package/dist/input-trace.cjs +56 -0
  54. package/dist/input-trace.d.cts +77 -0
  55. package/dist/input-trace.d.ts +77 -0
  56. package/dist/input-trace.js +55 -0
  57. package/dist/internal/annotations.cjs +316 -0
  58. package/dist/internal/annotations.d.cts +140 -0
  59. package/dist/internal/annotations.d.ts +140 -0
  60. package/dist/internal/annotations.js +306 -0
  61. package/dist/internal/dependency.cjs +984 -0
  62. package/dist/internal/dependency.d.cts +539 -0
  63. package/dist/internal/dependency.d.ts +539 -0
  64. package/dist/internal/dependency.js +964 -0
  65. package/dist/{mode-dispatch.cjs → internal/mode-dispatch.cjs} +1 -3
  66. package/dist/{mode-dispatch.d.cts → internal/mode-dispatch.d.cts} +3 -7
  67. package/dist/{mode-dispatch.d.ts → internal/mode-dispatch.d.ts} +3 -7
  68. package/dist/{mode-dispatch.js → internal/mode-dispatch.js} +1 -3
  69. package/dist/internal/parser.cjs +728 -0
  70. package/dist/internal/parser.d.cts +947 -0
  71. package/dist/internal/parser.d.ts +947 -0
  72. package/dist/internal/parser.js +711 -0
  73. package/dist/message.cjs +84 -26
  74. package/dist/message.d.cts +49 -9
  75. package/dist/message.d.ts +49 -9
  76. package/dist/message.js +84 -27
  77. package/dist/modifiers.cjs +1023 -240
  78. package/dist/modifiers.d.cts +42 -1
  79. package/dist/modifiers.d.ts +42 -1
  80. package/dist/modifiers.js +1023 -240
  81. package/dist/parser.cjs +11 -463
  82. package/dist/parser.d.cts +3 -537
  83. package/dist/parser.d.ts +3 -537
  84. package/dist/parser.js +2 -433
  85. package/dist/phase2-seed.cjs +59 -0
  86. package/dist/phase2-seed.js +56 -0
  87. package/dist/primitives.cjs +557 -208
  88. package/dist/primitives.d.cts +10 -14
  89. package/dist/primitives.d.ts +10 -14
  90. package/dist/primitives.js +557 -208
  91. package/dist/program.cjs +5 -1
  92. package/dist/program.d.cts +5 -3
  93. package/dist/program.d.ts +5 -3
  94. package/dist/program.js +6 -1
  95. package/dist/suggestion.cjs +22 -8
  96. package/dist/suggestion.js +22 -8
  97. package/dist/usage-internals.cjs +3 -2
  98. package/dist/usage-internals.js +4 -2
  99. package/dist/usage.cjs +195 -40
  100. package/dist/usage.d.cts +92 -11
  101. package/dist/usage.d.ts +92 -11
  102. package/dist/usage.js +194 -41
  103. package/dist/validate.cjs +170 -0
  104. package/dist/validate.js +164 -0
  105. package/dist/valueparser.cjs +1278 -191
  106. package/dist/valueparser.d.cts +330 -20
  107. package/dist/valueparser.d.ts +330 -20
  108. package/dist/valueparser.js +1277 -192
  109. package/package.json +9 -9
package/dist/parser.d.ts CHANGED
@@ -1,537 +1,3 @@
1
- import { ParseOptions } from "./annotations.js";
2
- import { Message } from "./message.js";
3
- import { Usage } from "./usage.js";
4
- import { DocFragments, DocPage } from "./doc.js";
5
- import { DependencyRegistryLike } from "./registry-types.js";
6
- import { ValueParserResult } from "./valueparser.js";
7
- import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
8
- import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
- import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
10
-
11
- //#region src/parser.d.ts
12
-
13
- /**
14
- * Represents the execution mode for parsers.
15
- *
16
- * - `"sync"`: Synchronous execution where methods return values directly.
17
- * - `"async"`: Asynchronous execution where methods return Promises or
18
- * AsyncIterables.
19
- *
20
- * @since 0.9.0
21
- */
22
- type Mode = "sync" | "async";
23
- /**
24
- * Wraps a value type based on the execution mode.
25
- *
26
- * - In sync mode: Returns `T` directly.
27
- * - In async mode: Returns `Promise<T>`.
28
- *
29
- * @template M The execution mode.
30
- * @template T The value type to wrap.
31
- * @since 0.9.0
32
- */
33
- type ModeValue<M extends Mode, T> = M extends "async" ? Promise<T> : T;
34
- /**
35
- * Wraps an iterable type based on the execution mode.
36
- *
37
- * - In sync mode: Returns `Iterable<T>`.
38
- * - In async mode: Returns `AsyncIterable<T>`.
39
- *
40
- * @template M The execution mode.
41
- * @template T The element type.
42
- * @since 0.9.0
43
- */
44
- type ModeIterable<M extends Mode, T> = M extends "async" ? AsyncIterable<T> : Iterable<T>;
45
- /**
46
- * Combines multiple modes into a single mode.
47
- * If any mode is `"async"`, the result is `"async"`; otherwise `"sync"`.
48
- *
49
- * @template T A tuple of Mode types.
50
- * @since 0.9.0
51
- */
52
- type CombineModes<T extends readonly Mode[]> = "async" extends T[number] ? "async" : "sync";
53
- /**
54
- * Represents the state passed to getDocFragments.
55
- * Can be either the actual parser state or an explicit indicator
56
- * that no state is available.
57
- * @template TState The type of the actual state when available.
58
- * @since 0.3.0
59
- */
60
- type DocState<TState> = {
61
- readonly kind: "available";
62
- readonly state: TState;
63
- } | {
64
- readonly kind: "unavailable";
65
- };
66
- /**
67
- * Parser interface for command-line argument parsing.
68
- * @template M The execution mode of the parser (`"sync"` or `"async"`).
69
- * @template TValue The type of the value returned by the parser.
70
- * @template TState The type of the state used during parsing.
71
- * @since 0.9.0 Added the `M` type parameter for sync/async mode support.
72
- */
73
- interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
74
- /**
75
- * A type tag for the result value of this parser, used for type inference.
76
- * Usually this is an empty array at runtime, but it does not matter
77
- * what it contains.
78
- * @internal
79
- */
80
- readonly $valueType: readonly TValue[];
81
- /**
82
- * A type tag for the state of this parser, used for type inference.
83
- * Usually this is an empty array at runtime, but it does not matter
84
- * what it contains.
85
- * @internal
86
- */
87
- readonly $stateType: readonly TState[];
88
- /**
89
- * The execution mode of this parser.
90
- *
91
- * - `"sync"`: All methods return values directly.
92
- * - `"async"`: Methods return Promises or AsyncIterables.
93
- *
94
- * @since 0.9.0
95
- */
96
- readonly $mode: M;
97
- /**
98
- * The priority of this parser, which determines the order in which
99
- * parsers are applied when multiple parsers are available. The greater
100
- * the number, the higher the priority.
101
- */
102
- readonly priority: number;
103
- /**
104
- * The usage information for this parser, which describes how
105
- * to use it in command-line interfaces.
106
- */
107
- readonly usage: Usage;
108
- /**
109
- * The initial state for this parser. This is used to initialize the
110
- * state when parsing starts.
111
- */
112
- readonly initialState: TState;
113
- /**
114
- * Parses the input context and returns a result indicating
115
- * whether the parsing was successful or not.
116
- * @param context The context of the parser, which includes the input buffer
117
- * and the current state.
118
- * @returns A result object indicating success or failure.
119
- * In async mode, returns a Promise that resolves to the result.
120
- */
121
- parse(context: ParserContext<TState>): ModeValue<M, ParserResult<TState>>;
122
- /**
123
- * Transforms a {@link TState} into a {@link TValue}, if applicable.
124
- * If the transformation is not applicable, it should return
125
- * a `ValueParserResult` with `success: false` and an appropriate error
126
- * message.
127
- * @param state The current state of the parser, which may contain accumulated
128
- * data or context needed to produce the final value.
129
- * @returns A result object indicating success or failure of
130
- * the transformation. If successful, it should contain
131
- * the parsed value of type {@link TValue}. If not applicable,
132
- * it should return an error message.
133
- * In async mode, returns a Promise that resolves to the result.
134
- */
135
- complete(state: TState): ModeValue<M, ValueParserResult<TValue>>;
136
- /**
137
- * Generates next-step suggestions based on the current context
138
- * and an optional prefix. This can be used to provide shell completion
139
- * suggestions or to guide users in constructing valid commands.
140
- * @param context The context of the parser, which includes the input buffer
141
- * and the current state.
142
- * @param prefix A prefix string that can be used to filter suggestions.
143
- * Can be an empty string if no prefix is provided.
144
- * @returns An iterable of {@link Suggestion} objects, each containing
145
- * a suggestion text and an optional description.
146
- * In async mode, returns an AsyncIterable.
147
- * @since 0.6.0
148
- */
149
- suggest(context: ParserContext<TState>, prefix: string): ModeIterable<M, Suggestion>;
150
- /**
151
- * Generates a documentation fragment for this parser, which can be used
152
- * to describe the parser's usage, description, and default value.
153
- * @param state The current state of the parser, wrapped in a DocState
154
- * to indicate whether the actual state is available or not.
155
- * @param defaultValue An optional default value that can be used
156
- * to provide a default value in the documentation.
157
- * @returns {@link DocFragments} object containing documentation
158
- * fragments for this parser.
159
- */
160
- getDocFragments(state: DocState<TState>, defaultValue?: TValue): DocFragments;
161
- }
162
- /**
163
- * The context of the parser, which includes the input buffer and the state.
164
- * @template TState The type of the state used during parsing.
165
- */
166
- interface ParserContext<TState> {
167
- /**
168
- * The array of input strings that the parser is currently processing.
169
- */
170
- readonly buffer: readonly string[];
171
- /**
172
- * The current state of the parser, which is used to track
173
- * the progress of parsing and any accumulated data.
174
- */
175
- readonly state: TState;
176
- /**
177
- * A flag indicating whether no more options should be parsed and instead
178
- * the remaining input should be treated as positional arguments.
179
- * This is typically set when the parser encounters a `--` in the input,
180
- * which is a common convention in command-line interfaces to indicate
181
- * that no further options should be processed.
182
- */
183
- readonly optionsTerminated: boolean;
184
- /**
185
- * Usage information for the entire parser tree.
186
- * Used to provide better error messages with suggestions for typos.
187
- * When a parser encounters an invalid option or command, it can use
188
- * this information to suggest similar valid options.
189
- * @since 0.7.0
190
- */
191
- readonly usage: Usage;
192
- /**
193
- * A registry containing resolved dependency values from DependencySource parsers.
194
- * This is used during shell completion to provide suggestions based on
195
- * the actual dependency values that have been parsed, rather than defaults.
196
- * @since 0.10.0
197
- */
198
- readonly dependencyRegistry?: DependencyRegistryLike;
199
- }
200
- /**
201
- * Represents a suggestion for command-line completion or guidance.
202
- * @since 0.6.0
203
- */
204
- type Suggestion = {
205
- /**
206
- * A literal text suggestion.
207
- */
208
- readonly kind: "literal";
209
- /**
210
- * The suggestion text that can be used for completion or guidance.
211
- */
212
- readonly text: string;
213
- /**
214
- * An optional description providing additional context
215
- * or information about the suggestion.
216
- */
217
- readonly description?: Message;
218
- } | {
219
- /**
220
- * A file system completion suggestion that uses native shell completion.
221
- */
222
- readonly kind: "file";
223
- /**
224
- * The current prefix/pattern for fallback when native completion is unavailable.
225
- */
226
- readonly pattern?: string;
227
- /**
228
- * The type of file system entries to complete.
229
- */
230
- readonly type: "file" | "directory" | "any";
231
- /**
232
- * File extensions to filter by (e.g., [".ts", ".js"]).
233
- */
234
- readonly extensions?: readonly string[];
235
- /**
236
- * Whether to include hidden files (those starting with a dot).
237
- */
238
- readonly includeHidden?: boolean;
239
- /**
240
- * An optional description providing additional context
241
- * or information about the suggestion.
242
- */
243
- readonly description?: Message;
244
- };
245
- /**
246
- * A discriminated union type representing the result of a parser operation.
247
- * It can either indicate a successful parse with the next state and context,
248
- * or a failure with an error message.
249
- * @template TState The type of the state after parsing. It should match with
250
- * the `TState` type of the {@link Parser} interface.
251
- */
252
- type ParserResult<TState> = {
253
- /**
254
- * Indicates that the parsing operation was successful.
255
- */
256
- readonly success: true;
257
- /**
258
- * The next context after parsing, which includes the updated input buffer.
259
- */
260
- readonly next: ParserContext<TState>;
261
- /**
262
- * The input elements consumed by the parser during this operation.
263
- */
264
- readonly consumed: readonly string[];
265
- } | {
266
- /**
267
- * Indicates that the parsing operation failed.
268
- */
269
- readonly success: false;
270
- /**
271
- * The number of the consumed input elements.
272
- */
273
- readonly consumed: number;
274
- /**
275
- * The error message describing why the parsing failed.
276
- */
277
- readonly error: Message;
278
- };
279
- /**
280
- * Infers the result value type of a {@link Parser}.
281
- * @template T The {@link Parser} to infer the result value type from.
282
- */
283
- type InferValue<T extends Parser<Mode, unknown, unknown>> = T["$valueType"][number];
284
- /**
285
- * Infers the execution mode of a {@link Parser}.
286
- * @template T The {@link Parser} to infer the execution mode from.
287
- * @since 0.9.0
288
- */
289
- type InferMode<T extends Parser<Mode, unknown, unknown>> = T["$mode"];
290
- /**
291
- * The result type of a whole parser operation, which can either be a successful
292
- * result with a value of type `T`, or a failure with an error message.
293
- * @template T The type of the value produced by the parser.
294
- */
295
- type Result<T> = {
296
- /**
297
- * Indicates that the parsing operation was successful.
298
- */
299
- success: true;
300
- /**
301
- * The successfully parsed value of type {@link T}.
302
- * This is the final result of the parsing operation after all parsers
303
- * have been applied and completed.
304
- */
305
- value: T;
306
- } | {
307
- /**
308
- * Indicates that the parsing operation failed.
309
- */
310
- success: false;
311
- /**
312
- * The error message describing why the parsing failed.
313
- */
314
- error: Message;
315
- };
316
- /**
317
- * Parses an array of command-line arguments using the provided combined parser.
318
- * This function processes the input arguments, applying the parser to each
319
- * argument until all arguments are consumed or an error occurs.
320
- *
321
- * This function only accepts synchronous parsers. For asynchronous parsers,
322
- * use {@link parseAsync}.
323
- *
324
- * @template T The type of the value produced by the parser.
325
- * @param parser The combined {@link Parser} to use for parsing the input
326
- * arguments. Must be a synchronous parser.
327
- * @param args The array of command-line arguments to parse. Usually this is
328
- * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
329
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
330
- * @returns A {@link Result} object indicating whether the parsing was
331
- * successful or not. If successful, it contains the parsed value of
332
- * type `T`. If not, it contains an error message describing the
333
- * failure.
334
- * @since 0.9.0 Renamed from the original `parse` function which now delegates
335
- * to this for sync parsers.
336
- * @since 0.10.0 Added optional `options` parameter for annotations support.
337
- */
338
- declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[], options?: ParseOptions): Result<T>;
339
- /**
340
- * Parses an array of command-line arguments using the provided combined parser.
341
- * This function processes the input arguments, applying the parser to each
342
- * argument until all arguments are consumed or an error occurs.
343
- *
344
- * This function accepts any parser (sync or async) and always returns a Promise.
345
- * For synchronous parsing with sync parsers, use {@link parseSync} instead.
346
- *
347
- * @template T The type of the value produced by the parser.
348
- * @param parser The combined {@link Parser} to use for parsing the input
349
- * arguments.
350
- * @param args The array of command-line arguments to parse. Usually this is
351
- * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
352
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
353
- * @returns A Promise that resolves to a {@link Result} object indicating
354
- * whether the parsing was successful or not.
355
- * @since 0.9.0
356
- * @since 0.10.0 Added optional `options` parameter for annotations support.
357
- */
358
- declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[], options?: ParseOptions): Promise<Result<T>>;
359
- /**
360
- * Parses an array of command-line arguments using the provided combined parser.
361
- * This function processes the input arguments, applying the parser to each
362
- * argument until all arguments are consumed or an error occurs.
363
- *
364
- * The return type depends on the parser's mode:
365
- * - Sync parsers return `Result<T>` directly.
366
- * - Async parsers return `Promise<Result<T>>`.
367
- *
368
- * For explicit control, use {@link parseSync} or {@link parseAsync}.
369
- *
370
- * @template M The execution mode of the parser.
371
- * @template T The type of the value produced by the parser.
372
- * @param parser The combined {@link Parser} to use for parsing the input
373
- * arguments.
374
- * @param args The array of command-line arguments to parse. Usually this is
375
- * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
376
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
377
- * @returns A {@link Result} object (for sync) or Promise thereof (for async)
378
- * indicating whether the parsing was successful or not.
379
- * @since 0.10.0 Added optional `options` parameter for annotations support.
380
- */
381
- declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[], options?: ParseOptions): ModeValue<M, Result<T>>;
382
- /**
383
- * Generates command-line suggestions based on current parsing state.
384
- * This function processes the input arguments up to the last argument,
385
- * then calls the parser's suggest method with the remaining prefix.
386
- *
387
- * This function only accepts synchronous parsers. For asynchronous parsers,
388
- * use {@link suggestAsync}.
389
- *
390
- * @template T The type of the value produced by the parser.
391
- * @param parser The {@link Parser} to use for generating suggestions.
392
- * Must be a synchronous parser.
393
- * @param args The array of command-line arguments including the partial
394
- * argument to complete. The last element is treated as
395
- * the prefix for suggestions.
396
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
397
- * @returns An array of {@link Suggestion} objects containing completion
398
- * candidates.
399
- * @example
400
- * ```typescript
401
- * const parser = object({
402
- * verbose: option("-v", "--verbose"),
403
- * format: option("-f", "--format", choice(["json", "yaml"]))
404
- * });
405
- *
406
- * // Get suggestions for options starting with "--"
407
- * const suggestions = suggestSync(parser, ["--"]);
408
- * // Returns: [{ text: "--verbose" }, { text: "--format" }]
409
- *
410
- * // Get suggestions after parsing some arguments
411
- * const suggestions2 = suggestSync(parser, ["-v", "--format="]);
412
- * // Returns: [{ text: "--format=json" }, { text: "--format=yaml" }]
413
- * ```
414
- * @since 0.6.0
415
- * @since 0.9.0 Renamed from the original `suggest` function.
416
- * @since 0.10.0 Added optional `options` parameter for annotations support.
417
- */
418
- declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): readonly Suggestion[];
419
- /**
420
- * Generates command-line suggestions based on current parsing state.
421
- * This function processes the input arguments up to the last argument,
422
- * then calls the parser's suggest method with the remaining prefix.
423
- *
424
- * This function accepts any parser (sync or async) and always returns a Promise.
425
- * For synchronous suggestion generation with sync parsers, use
426
- * {@link suggestSync} instead.
427
- *
428
- * @template T The type of the value produced by the parser.
429
- * @param parser The {@link Parser} to use for generating suggestions.
430
- * @param args The array of command-line arguments including the partial
431
- * argument to complete. The last element is treated as
432
- * the prefix for suggestions.
433
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
434
- * @returns A Promise that resolves to an array of {@link Suggestion} objects
435
- * containing completion candidates.
436
- * @since 0.9.0
437
- * @since 0.10.0 Added optional `options` parameter for annotations support.
438
- */
439
- declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): Promise<readonly Suggestion[]>;
440
- /**
441
- * Generates command-line suggestions based on current parsing state.
442
- * This function processes the input arguments up to the last argument,
443
- * then calls the parser's suggest method with the remaining prefix.
444
- *
445
- * The return type depends on the parser's mode:
446
- * - Sync parsers return `readonly Suggestion[]` directly.
447
- * - Async parsers return `Promise<readonly Suggestion[]>`.
448
- *
449
- * For explicit control, use {@link suggestSync} or {@link suggestAsync}.
450
- *
451
- * @template M The execution mode of the parser.
452
- * @template T The type of the value produced by the parser.
453
- * @param parser The {@link Parser} to use for generating suggestions.
454
- * @param args The array of command-line arguments including the partial
455
- * argument to complete. The last element is treated as
456
- * the prefix for suggestions.
457
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
458
- * @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
459
- * (for async) containing completion candidates.
460
- * @since 0.6.0
461
- * @since 0.10.0 Added optional `options` parameter for annotations support.
462
- */
463
- declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly [string, ...readonly string[]], options?: ParseOptions): ModeValue<M, readonly Suggestion[]>;
464
- /**
465
- * Generates a documentation page for a synchronous parser.
466
- *
467
- * This is the sync-specific version of {@link getDocPage}. It only accepts
468
- * sync parsers and returns the documentation page directly (not wrapped
469
- * in a Promise).
470
- *
471
- * @param parser The sync parser to generate documentation for.
472
- * @param args Optional array of command-line arguments for context.
473
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
474
- * @returns A {@link DocPage} or `undefined`.
475
- * @since 0.9.0
476
- * @since 0.10.0 Added optional `options` parameter for annotations support.
477
- */
478
- declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?: readonly string[], options?: ParseOptions): DocPage | undefined;
479
- /**
480
- * Generates a documentation page for any parser, returning a Promise.
481
- *
482
- * This function accepts parsers of any mode (sync or async) and always
483
- * returns a Promise. Use this when working with parsers that may contain
484
- * async value parsers.
485
- *
486
- * @param parser The parser to generate documentation for.
487
- * @param args Optional array of command-line arguments for context.
488
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
489
- * @returns A Promise of {@link DocPage} or `undefined`.
490
- * @since 0.9.0
491
- * @since 0.10.0 Added optional `options` parameter for annotations support.
492
- */
493
- declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
494
- /**
495
- * Generates a documentation page for a parser based on its current state after
496
- * attempting to parse the provided arguments. This function is useful for
497
- * creating help documentation that reflects the current parsing context.
498
- *
499
- * The function works by:
500
- * 1. Attempting to parse the provided arguments to determine the current state
501
- * 2. Generating documentation fragments from the parser's current state
502
- * 3. Organizing fragments into entries and sections
503
- * 4. Resolving command usage terms based on parsed arguments
504
- *
505
- * For sync parsers, returns the documentation page directly.
506
- * For async parsers, returns a Promise of the documentation page.
507
- *
508
- * @param parser The parser to generate documentation for
509
- * @param args Optional array of command-line arguments that have been parsed
510
- * so far. Defaults to an empty array. This is used to determine
511
- * the current parsing context and generate contextual documentation.
512
- * @param options Optional {@link ParseOptions} for customizing parsing behavior.
513
- * @returns For sync parsers, returns a {@link DocPage} directly.
514
- * For async parsers, returns a Promise of {@link DocPage}.
515
- * Returns `undefined` if no documentation can be generated.
516
- *
517
- * @example
518
- * ```typescript
519
- * const parser = object({
520
- * verbose: option("-v", "--verbose"),
521
- * port: option("-p", "--port", integer())
522
- * });
523
- *
524
- * // Get documentation for sync parser
525
- * const rootDoc = getDocPage(parser);
526
- *
527
- * // Get documentation for async parser
528
- * const asyncDoc = await getDocPage(asyncParser);
529
- * ```
530
- * @since 0.9.0 Updated to support async parsers.
531
- * @since 0.10.0 Added optional `options` parameter for annotations support.
532
- */
533
- declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: readonly string[], options?: ParseOptions): DocPage | undefined;
534
- declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
535
- declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[], options?: ParseOptions): ModeValue<M, DocPage | undefined>;
536
- //#endregion
537
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, GroupOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
1
+ import { ParseOptions } from "./internal/annotations.js";
2
+ import { CombineModes, DocState, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.js";
3
+ export { type CombineModes, type DocState, type ExecutionContext, type ExecutionPhase, type InferMode, type InferValue, type Mode, type ModeIterable, type ModeValue, type ParseFrame, type ParseOptions, type Parser, type ParserContext, type ParserResult, type Result, type Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync };