@optique/core 0.9.0-dev.196 → 0.9.0-dev.202

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/parser.cjs CHANGED
@@ -9,17 +9,23 @@ const require_primitives = require('./primitives.cjs');
9
9
  * Parses an array of command-line arguments using the provided combined parser.
10
10
  * This function processes the input arguments, applying the parser to each
11
11
  * argument until all arguments are consumed or an error occurs.
12
+ *
13
+ * This function only accepts synchronous parsers. For asynchronous parsers,
14
+ * use {@link parseAsync}.
15
+ *
12
16
  * @template T The type of the value produced by the parser.
13
17
  * @param parser The combined {@link Parser} to use for parsing the input
14
- * arguments.
18
+ * arguments. Must be a synchronous parser.
15
19
  * @param args The array of command-line arguments to parse. Usually this is
16
20
  * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
17
21
  * @returns A {@link Result} object indicating whether the parsing was
18
22
  * successful or not. If successful, it contains the parsed value of
19
23
  * type `T`. If not, it contains an error message describing the
20
24
  * failure.
25
+ * @since 0.9.0 Renamed from the original `parse` function which now delegates
26
+ * to this for sync parsers.
21
27
  */
22
- function parse(parser, args) {
28
+ function parseSync(parser, args) {
23
29
  let context = {
24
30
  buffer: args,
25
31
  optionsTerminated: false,
@@ -49,11 +55,86 @@ function parse(parser, args) {
49
55
  };
50
56
  }
51
57
  /**
58
+ * Parses an array of command-line arguments using the provided combined parser.
59
+ * This function processes the input arguments, applying the parser to each
60
+ * argument until all arguments are consumed or an error occurs.
61
+ *
62
+ * This function accepts any parser (sync or async) and always returns a Promise.
63
+ * For synchronous parsing with sync parsers, use {@link parseSync} instead.
64
+ *
65
+ * @template T The type of the value produced by the parser.
66
+ * @param parser The combined {@link Parser} to use for parsing the input
67
+ * arguments.
68
+ * @param args The array of command-line arguments to parse. Usually this is
69
+ * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
70
+ * @returns A Promise that resolves to a {@link Result} object indicating
71
+ * whether the parsing was successful or not.
72
+ * @since 0.9.0
73
+ */
74
+ async function parseAsync(parser, args) {
75
+ let context = {
76
+ buffer: args,
77
+ optionsTerminated: false,
78
+ state: parser.initialState,
79
+ usage: parser.usage
80
+ };
81
+ do {
82
+ const result = await parser.parse(context);
83
+ if (!result.success) return {
84
+ success: false,
85
+ error: result.error
86
+ };
87
+ const previousBuffer = context.buffer;
88
+ context = result.next;
89
+ if (context.buffer.length > 0 && context.buffer.length === previousBuffer.length && context.buffer.every((item, i) => item === previousBuffer[i])) return {
90
+ success: false,
91
+ error: require_message.message`Unexpected option or argument: ${context.buffer[0]}.`
92
+ };
93
+ } while (context.buffer.length > 0);
94
+ const endResult = await parser.complete(context.state);
95
+ return endResult.success ? {
96
+ success: true,
97
+ value: endResult.value
98
+ } : {
99
+ success: false,
100
+ error: endResult.error
101
+ };
102
+ }
103
+ /**
104
+ * Parses an array of command-line arguments using the provided combined parser.
105
+ * This function processes the input arguments, applying the parser to each
106
+ * argument until all arguments are consumed or an error occurs.
107
+ *
108
+ * The return type depends on the parser's mode:
109
+ * - Sync parsers return `Result<T>` directly.
110
+ * - Async parsers return `Promise<Result<T>>`.
111
+ *
112
+ * For explicit control, use {@link parseSync} or {@link parseAsync}.
113
+ *
114
+ * @template M The execution mode of the parser.
115
+ * @template T The type of the value produced by the parser.
116
+ * @param parser The combined {@link Parser} to use for parsing the input
117
+ * arguments.
118
+ * @param args The array of command-line arguments to parse. Usually this is
119
+ * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
120
+ * @returns A {@link Result} object (for sync) or Promise thereof (for async)
121
+ * indicating whether the parsing was successful or not.
122
+ */
123
+ function parse(parser, args) {
124
+ if (parser.$mode === "async") return parseAsync(parser, args);
125
+ return parseSync(parser, args);
126
+ }
127
+ /**
52
128
  * Generates command-line suggestions based on current parsing state.
53
129
  * This function processes the input arguments up to the last argument,
54
130
  * then calls the parser's suggest method with the remaining prefix.
131
+ *
132
+ * This function only accepts synchronous parsers. For asynchronous parsers,
133
+ * use {@link suggestAsync}.
134
+ *
55
135
  * @template T The type of the value produced by the parser.
56
136
  * @param parser The {@link Parser} to use for generating suggestions.
137
+ * Must be a synchronous parser.
57
138
  * @param args The array of command-line arguments including the partial
58
139
  * argument to complete. The last element is treated as
59
140
  * the prefix for suggestions.
@@ -67,16 +148,17 @@ function parse(parser, args) {
67
148
  * });
68
149
  *
69
150
  * // Get suggestions for options starting with "--"
70
- * const suggestions = suggest(parser, ["--"]);
151
+ * const suggestions = suggestSync(parser, ["--"]);
71
152
  * // Returns: [{ text: "--verbose" }, { text: "--format" }]
72
153
  *
73
154
  * // Get suggestions after parsing some arguments
74
- * const suggestions2 = suggest(parser, ["-v", "--format="]);
155
+ * const suggestions2 = suggestSync(parser, ["-v", "--format="]);
75
156
  * // Returns: [{ text: "--format=json" }, { text: "--format=yaml" }]
76
157
  * ```
77
158
  * @since 0.6.0
159
+ * @since 0.9.0 Renamed from the original `suggest` function.
78
160
  */
79
- function suggest(parser, args) {
161
+ function suggestSync(parser, args) {
80
162
  const allButLast = args.slice(0, -1);
81
163
  const prefix = args[args.length - 1];
82
164
  let context = {
@@ -95,6 +177,93 @@ function suggest(parser, args) {
95
177
  return Array.from(parser.suggest(context, prefix));
96
178
  }
97
179
  /**
180
+ * Generates command-line suggestions based on current parsing state.
181
+ * This function processes the input arguments up to the last argument,
182
+ * then calls the parser's suggest method with the remaining prefix.
183
+ *
184
+ * This function accepts any parser (sync or async) and always returns a Promise.
185
+ * For synchronous suggestion generation with sync parsers, use
186
+ * {@link suggestSync} instead.
187
+ *
188
+ * @template T The type of the value produced by the parser.
189
+ * @param parser The {@link Parser} to use for generating suggestions.
190
+ * @param args The array of command-line arguments including the partial
191
+ * argument to complete. The last element is treated as
192
+ * the prefix for suggestions.
193
+ * @returns A Promise that resolves to an array of {@link Suggestion} objects
194
+ * containing completion candidates.
195
+ * @since 0.9.0
196
+ */
197
+ async function suggestAsync(parser, args) {
198
+ const allButLast = args.slice(0, -1);
199
+ const prefix = args[args.length - 1];
200
+ let context = {
201
+ buffer: allButLast,
202
+ optionsTerminated: false,
203
+ state: parser.initialState,
204
+ usage: parser.usage
205
+ };
206
+ while (context.buffer.length > 0) {
207
+ const result = await parser.parse(context);
208
+ if (!result.success) {
209
+ const suggestions$1 = [];
210
+ for await (const suggestion of parser.suggest(context, prefix)) suggestions$1.push(suggestion);
211
+ return suggestions$1;
212
+ }
213
+ const previousBuffer = context.buffer;
214
+ context = result.next;
215
+ if (context.buffer.length > 0 && context.buffer.length === previousBuffer.length && context.buffer.every((item, i) => item === previousBuffer[i])) return [];
216
+ }
217
+ const suggestions = [];
218
+ for await (const suggestion of parser.suggest(context, prefix)) suggestions.push(suggestion);
219
+ return suggestions;
220
+ }
221
+ /**
222
+ * Generates command-line suggestions based on current parsing state.
223
+ * This function processes the input arguments up to the last argument,
224
+ * then calls the parser's suggest method with the remaining prefix.
225
+ *
226
+ * The return type depends on the parser's mode:
227
+ * - Sync parsers return `readonly Suggestion[]` directly.
228
+ * - Async parsers return `Promise<readonly Suggestion[]>`.
229
+ *
230
+ * For explicit control, use {@link suggestSync} or {@link suggestAsync}.
231
+ *
232
+ * @template M The execution mode of the parser.
233
+ * @template T The type of the value produced by the parser.
234
+ * @param parser The {@link Parser} to use for generating suggestions.
235
+ * @param args The array of command-line arguments including the partial
236
+ * argument to complete. The last element is treated as
237
+ * the prefix for suggestions.
238
+ * @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
239
+ * (for async) containing completion candidates.
240
+ * @since 0.6.0
241
+ */
242
+ function suggest(parser, args) {
243
+ if (parser.$mode === "async") return suggestAsync(parser, args);
244
+ return suggestSync(parser, args);
245
+ }
246
+ /**
247
+ * Recursively searches for a command within nested exclusive usage terms.
248
+ * When the command is found, returns the expanded usage terms for that command.
249
+ *
250
+ * @param term The usage term to search in
251
+ * @param commandName The command name to find
252
+ * @returns The expanded usage terms if found, null otherwise
253
+ */
254
+ function findCommandInExclusive(term, commandName) {
255
+ if (term.type !== "exclusive") return null;
256
+ for (const termGroup of term.terms) {
257
+ const firstTerm = termGroup[0];
258
+ if (firstTerm?.type === "command" && firstTerm.name === commandName) return termGroup;
259
+ if (firstTerm?.type === "exclusive") {
260
+ const found = findCommandInExclusive(firstTerm, commandName);
261
+ if (found) return [...found, ...termGroup.slice(1)];
262
+ }
263
+ }
264
+ return null;
265
+ }
266
+ /**
98
267
  * Generates a documentation page for a parser based on its current state after
99
268
  * attempting to parse the provided arguments. This function is useful for
100
269
  * creating help documentation that reflects the current parsing context.
@@ -157,14 +326,11 @@ function getDocPage(parser, args = []) {
157
326
  if (i >= usage.length) break;
158
327
  const term = usage[i];
159
328
  if (term.type === "exclusive") {
160
- for (const termGroup of term.terms) {
161
- const firstTerm = termGroup[0];
162
- if (firstTerm?.type !== "command" || firstTerm.name !== arg) continue;
163
- usage.splice(i, 1, ...termGroup);
164
- i += termGroup.length;
165
- break;
166
- }
167
- if (usage[i] === term) i++;
329
+ const found = findCommandInExclusive(term, arg);
330
+ if (found) {
331
+ usage.splice(i, 1, ...found);
332
+ i += found.length;
333
+ } else i++;
168
334
  } else i++;
169
335
  }
170
336
  return {
@@ -195,7 +361,11 @@ exports.option = require_primitives.option;
195
361
  exports.optional = require_modifiers.optional;
196
362
  exports.or = require_constructs.or;
197
363
  exports.parse = parse;
364
+ exports.parseAsync = parseAsync;
365
+ exports.parseSync = parseSync;
198
366
  exports.passThrough = require_primitives.passThrough;
199
367
  exports.suggest = suggest;
368
+ exports.suggestAsync = suggestAsync;
369
+ exports.suggestSync = suggestSync;
200
370
  exports.tuple = require_constructs.tuple;
201
371
  exports.withDefault = require_modifiers.withDefault;
package/dist/parser.d.cts CHANGED
@@ -8,6 +8,46 @@ import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, Long
8
8
 
9
9
  //#region src/parser.d.ts
10
10
 
11
+ /**
12
+ * Represents the execution mode for parsers.
13
+ *
14
+ * - `"sync"`: Synchronous execution where methods return values directly.
15
+ * - `"async"`: Asynchronous execution where methods return Promises or
16
+ * AsyncIterables.
17
+ *
18
+ * @since 0.9.0
19
+ */
20
+ type Mode = "sync" | "async";
21
+ /**
22
+ * Wraps a value type based on the execution mode.
23
+ *
24
+ * - In sync mode: Returns `T` directly.
25
+ * - In async mode: Returns `Promise<T>`.
26
+ *
27
+ * @template M The execution mode.
28
+ * @template T The value type to wrap.
29
+ * @since 0.9.0
30
+ */
31
+ type ModeValue<M extends Mode, T> = M extends "async" ? Promise<T> : T;
32
+ /**
33
+ * Wraps an iterable type based on the execution mode.
34
+ *
35
+ * - In sync mode: Returns `Iterable<T>`.
36
+ * - In async mode: Returns `AsyncIterable<T>`.
37
+ *
38
+ * @template M The execution mode.
39
+ * @template T The element type.
40
+ * @since 0.9.0
41
+ */
42
+ type ModeIterable<M extends Mode, T> = M extends "async" ? AsyncIterable<T> : Iterable<T>;
43
+ /**
44
+ * Combines multiple modes into a single mode.
45
+ * If any mode is `"async"`, the result is `"async"`; otherwise `"sync"`.
46
+ *
47
+ * @template T A tuple of Mode types.
48
+ * @since 0.9.0
49
+ */
50
+ type CombineModes<T extends readonly Mode[]> = "async" extends T[number] ? "async" : "sync";
11
51
  /**
12
52
  * Represents the state passed to getDocFragments.
13
53
  * Can be either the actual parser state or an explicit indicator
@@ -23,10 +63,12 @@ type DocState<TState> = {
23
63
  };
24
64
  /**
25
65
  * Parser interface for command-line argument parsing.
66
+ * @template M The execution mode of the parser (`"sync"` or `"async"`).
26
67
  * @template TValue The type of the value returned by the parser.
27
68
  * @template TState The type of the state used during parsing.
69
+ * @since 0.9.0 Added the `M` type parameter for sync/async mode support.
28
70
  */
29
- interface Parser<TValue, TState> {
71
+ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
30
72
  /**
31
73
  * A type tag for the result value of this parser, used for type inference.
32
74
  * Usually this is an empty array at runtime, but it does not matter
@@ -41,6 +83,15 @@ interface Parser<TValue, TState> {
41
83
  * @internal
42
84
  */
43
85
  readonly $stateType: readonly TState[];
86
+ /**
87
+ * The execution mode of this parser.
88
+ *
89
+ * - `"sync"`: All methods return values directly.
90
+ * - `"async"`: Methods return Promises or AsyncIterables.
91
+ *
92
+ * @since 0.9.0
93
+ */
94
+ readonly $mode: M;
44
95
  /**
45
96
  * The priority of this parser, which determines the order in which
46
97
  * parsers are applied when multiple parsers are available. The greater
@@ -63,8 +114,9 @@ interface Parser<TValue, TState> {
63
114
  * @param context The context of the parser, which includes the input buffer
64
115
  * and the current state.
65
116
  * @returns A result object indicating success or failure.
117
+ * In async mode, returns a Promise that resolves to the result.
66
118
  */
67
- parse(context: ParserContext<TState>): ParserResult<TState>;
119
+ parse(context: ParserContext<TState>): ModeValue<M, ParserResult<TState>>;
68
120
  /**
69
121
  * Transforms a {@link TState} into a {@link TValue}, if applicable.
70
122
  * If the transformation is not applicable, it should return
@@ -76,8 +128,9 @@ interface Parser<TValue, TState> {
76
128
  * the transformation. If successful, it should contain
77
129
  * the parsed value of type {@link TValue}. If not applicable,
78
130
  * it should return an error message.
131
+ * In async mode, returns a Promise that resolves to the result.
79
132
  */
80
- complete(state: TState): ValueParserResult<TValue>;
133
+ complete(state: TState): ModeValue<M, ValueParserResult<TValue>>;
81
134
  /**
82
135
  * Generates next-step suggestions based on the current context
83
136
  * and an optional prefix. This can be used to provide shell completion
@@ -88,9 +141,10 @@ interface Parser<TValue, TState> {
88
141
  * Can be an empty string if no prefix is provided.
89
142
  * @returns An iterable of {@link Suggestion} objects, each containing
90
143
  * a suggestion text and an optional description.
144
+ * In async mode, returns an AsyncIterable.
91
145
  * @since 0.6.0
92
146
  */
93
- suggest(context: ParserContext<TState>, prefix: string): Iterable<Suggestion>;
147
+ suggest(context: ParserContext<TState>, prefix: string): ModeIterable<M, Suggestion>;
94
148
  /**
95
149
  * Generates a documentation fragment for this parser, which can be used
96
150
  * to describe the parser's usage, description, and default value.
@@ -217,7 +271,13 @@ type ParserResult<TState> = {
217
271
  * Infers the result value type of a {@link Parser}.
218
272
  * @template T The {@link Parser} to infer the result value type from.
219
273
  */
220
- type InferValue<T extends Parser<unknown, unknown>> = T["$valueType"][number];
274
+ type InferValue<T extends Parser<Mode, unknown, unknown>> = T["$valueType"][number];
275
+ /**
276
+ * Infers the execution mode of a {@link Parser}.
277
+ * @template T The {@link Parser} to infer the execution mode from.
278
+ * @since 0.9.0
279
+ */
280
+ type InferMode<T extends Parser<Mode, unknown, unknown>> = T["$mode"];
221
281
  /**
222
282
  * The result type of a whole parser operation, which can either be a successful
223
283
  * result with a value of type `T`, or a failure with an error message.
@@ -248,23 +308,73 @@ type Result<T> = {
248
308
  * Parses an array of command-line arguments using the provided combined parser.
249
309
  * This function processes the input arguments, applying the parser to each
250
310
  * argument until all arguments are consumed or an error occurs.
311
+ *
312
+ * This function only accepts synchronous parsers. For asynchronous parsers,
313
+ * use {@link parseAsync}.
314
+ *
251
315
  * @template T The type of the value produced by the parser.
252
316
  * @param parser The combined {@link Parser} to use for parsing the input
253
- * arguments.
317
+ * arguments. Must be a synchronous parser.
254
318
  * @param args The array of command-line arguments to parse. Usually this is
255
319
  * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
256
320
  * @returns A {@link Result} object indicating whether the parsing was
257
321
  * successful or not. If successful, it contains the parsed value of
258
322
  * type `T`. If not, it contains an error message describing the
259
323
  * failure.
324
+ * @since 0.9.0 Renamed from the original `parse` function which now delegates
325
+ * to this for sync parsers.
260
326
  */
261
- declare function parse<T>(parser: Parser<T, unknown>, args: readonly string[]): Result<T>;
327
+ declare function parseSync<T>(parser: Parser<"sync", T, unknown>, args: readonly string[]): Result<T>;
328
+ /**
329
+ * Parses an array of command-line arguments using the provided combined parser.
330
+ * This function processes the input arguments, applying the parser to each
331
+ * argument until all arguments are consumed or an error occurs.
332
+ *
333
+ * This function accepts any parser (sync or async) and always returns a Promise.
334
+ * For synchronous parsing with sync parsers, use {@link parseSync} instead.
335
+ *
336
+ * @template T The type of the value produced by the parser.
337
+ * @param parser The combined {@link Parser} to use for parsing the input
338
+ * arguments.
339
+ * @param args The array of command-line arguments to parse. Usually this is
340
+ * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
341
+ * @returns A Promise that resolves to a {@link Result} object indicating
342
+ * whether the parsing was successful or not.
343
+ * @since 0.9.0
344
+ */
345
+ declare function parseAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly string[]): Promise<Result<T>>;
346
+ /**
347
+ * Parses an array of command-line arguments using the provided combined parser.
348
+ * This function processes the input arguments, applying the parser to each
349
+ * argument until all arguments are consumed or an error occurs.
350
+ *
351
+ * The return type depends on the parser's mode:
352
+ * - Sync parsers return `Result<T>` directly.
353
+ * - Async parsers return `Promise<Result<T>>`.
354
+ *
355
+ * For explicit control, use {@link parseSync} or {@link parseAsync}.
356
+ *
357
+ * @template M The execution mode of the parser.
358
+ * @template T The type of the value produced by the parser.
359
+ * @param parser The combined {@link Parser} to use for parsing the input
360
+ * arguments.
361
+ * @param args The array of command-line arguments to parse. Usually this is
362
+ * `process.argv.slice(2)` in Node.js or `Deno.args` in Deno.
363
+ * @returns A {@link Result} object (for sync) or Promise thereof (for async)
364
+ * indicating whether the parsing was successful or not.
365
+ */
366
+ declare function parse<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly string[]): ModeValue<M, Result<T>>;
262
367
  /**
263
368
  * Generates command-line suggestions based on current parsing state.
264
369
  * This function processes the input arguments up to the last argument,
265
370
  * then calls the parser's suggest method with the remaining prefix.
371
+ *
372
+ * This function only accepts synchronous parsers. For asynchronous parsers,
373
+ * use {@link suggestAsync}.
374
+ *
266
375
  * @template T The type of the value produced by the parser.
267
376
  * @param parser The {@link Parser} to use for generating suggestions.
377
+ * Must be a synchronous parser.
268
378
  * @param args The array of command-line arguments including the partial
269
379
  * argument to complete. The last element is treated as
270
380
  * the prefix for suggestions.
@@ -278,16 +388,58 @@ declare function parse<T>(parser: Parser<T, unknown>, args: readonly string[]):
278
388
  * });
279
389
  *
280
390
  * // Get suggestions for options starting with "--"
281
- * const suggestions = suggest(parser, ["--"]);
391
+ * const suggestions = suggestSync(parser, ["--"]);
282
392
  * // Returns: [{ text: "--verbose" }, { text: "--format" }]
283
393
  *
284
394
  * // Get suggestions after parsing some arguments
285
- * const suggestions2 = suggest(parser, ["-v", "--format="]);
395
+ * const suggestions2 = suggestSync(parser, ["-v", "--format="]);
286
396
  * // Returns: [{ text: "--format=json" }, { text: "--format=yaml" }]
287
397
  * ```
288
398
  * @since 0.6.0
399
+ * @since 0.9.0 Renamed from the original `suggest` function.
400
+ */
401
+ declare function suggestSync<T>(parser: Parser<"sync", T, unknown>, args: readonly [string, ...readonly string[]]): readonly Suggestion[];
402
+ /**
403
+ * Generates command-line suggestions based on current parsing state.
404
+ * This function processes the input arguments up to the last argument,
405
+ * then calls the parser's suggest method with the remaining prefix.
406
+ *
407
+ * This function accepts any parser (sync or async) and always returns a Promise.
408
+ * For synchronous suggestion generation with sync parsers, use
409
+ * {@link suggestSync} instead.
410
+ *
411
+ * @template T The type of the value produced by the parser.
412
+ * @param parser The {@link Parser} to use for generating suggestions.
413
+ * @param args The array of command-line arguments including the partial
414
+ * argument to complete. The last element is treated as
415
+ * the prefix for suggestions.
416
+ * @returns A Promise that resolves to an array of {@link Suggestion} objects
417
+ * containing completion candidates.
418
+ * @since 0.9.0
419
+ */
420
+ declare function suggestAsync<T>(parser: Parser<Mode, T, unknown>, args: readonly [string, ...readonly string[]]): Promise<readonly Suggestion[]>;
421
+ /**
422
+ * Generates command-line suggestions based on current parsing state.
423
+ * This function processes the input arguments up to the last argument,
424
+ * then calls the parser's suggest method with the remaining prefix.
425
+ *
426
+ * The return type depends on the parser's mode:
427
+ * - Sync parsers return `readonly Suggestion[]` directly.
428
+ * - Async parsers return `Promise<readonly Suggestion[]>`.
429
+ *
430
+ * For explicit control, use {@link suggestSync} or {@link suggestAsync}.
431
+ *
432
+ * @template M The execution mode of the parser.
433
+ * @template T The type of the value produced by the parser.
434
+ * @param parser The {@link Parser} to use for generating suggestions.
435
+ * @param args The array of command-line arguments including the partial
436
+ * argument to complete. The last element is treated as
437
+ * the prefix for suggestions.
438
+ * @returns An array of {@link Suggestion} objects (for sync) or Promise thereof
439
+ * (for async) containing completion candidates.
440
+ * @since 0.6.0
289
441
  */
290
- declare function suggest<T>(parser: Parser<T, unknown>, args: readonly [string, ...readonly string[]]): readonly Suggestion[];
442
+ declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args: readonly [string, ...readonly string[]]): ModeValue<M, readonly Suggestion[]>;
291
443
  /**
292
444
  * Generates a documentation page for a parser based on its current state after
293
445
  * attempting to parse the provided arguments. This function is useful for
@@ -321,6 +473,6 @@ declare function suggest<T>(parser: Parser<T, unknown>, args: readonly [string,
321
473
  * const contextDoc = getDocPage(parser, ["-v"]);
322
474
  * ```
323
475
  */
324
- declare function getDocPage(parser: Parser<unknown, unknown>, args?: readonly string[]): DocPage | undefined;
476
+ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: readonly string[]): DocPage | undefined;
325
477
  //#endregion
326
- export { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, passThrough, suggest, tuple, withDefault };
478
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, group, longestMatch, map, merge, multiple, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };