@optique/core 0.10.0-dev.293 → 0.10.0-dev.295
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/constructs.cjs +226 -60
- package/dist/constructs.js +227 -61
- package/dist/dependency.cjs +66 -1
- package/dist/dependency.d.cts +79 -2
- package/dist/dependency.d.ts +79 -2
- package/dist/dependency.js +60 -1
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/modifiers.cjs +16 -0
- package/dist/modifiers.js +16 -0
- package/dist/primitives.cjs +7 -2
- package/dist/primitives.d.cts +4 -3
- package/dist/primitives.d.ts +4 -3
- package/dist/primitives.js +8 -3
- package/package.json +1 -1
package/dist/dependency.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ declare const DerivedValueParserMarker: unique symbol;
|
|
|
24
24
|
* @since 0.10.0
|
|
25
25
|
*/
|
|
26
26
|
declare const DependencyId: unique symbol;
|
|
27
|
+
/**
|
|
28
|
+
* A unique symbol used to store multiple dependency IDs on derived parsers
|
|
29
|
+
* that depend on multiple sources (created via {@link deriveFrom}).
|
|
30
|
+
* @since 0.10.0
|
|
31
|
+
*/
|
|
32
|
+
declare const DependencyIds: unique symbol;
|
|
27
33
|
/**
|
|
28
34
|
* A unique symbol used to access the parseWithDependency method on derived parsers.
|
|
29
35
|
* @since 0.10.0
|
|
@@ -308,9 +314,19 @@ interface DerivedValueParser<M extends Mode = "sync", T = unknown, S = unknown>
|
|
|
308
314
|
readonly [DerivedValueParserMarker]: true;
|
|
309
315
|
/**
|
|
310
316
|
* The unique identifier of the dependency source this parser depends on.
|
|
317
|
+
* For parsers created with {@link deriveFrom} that have multiple dependencies,
|
|
318
|
+
* this is set to the first dependency's ID for backwards compatibility.
|
|
311
319
|
* @internal
|
|
312
320
|
*/
|
|
313
321
|
readonly [DependencyId]: symbol;
|
|
322
|
+
/**
|
|
323
|
+
* The unique identifiers of all dependency sources this parser depends on.
|
|
324
|
+
* Present only for parsers created with {@link deriveFrom} that have multiple
|
|
325
|
+
* dependencies. If present, this takes precedence over {@link DependencyId}
|
|
326
|
+
* during dependency resolution.
|
|
327
|
+
* @internal
|
|
328
|
+
*/
|
|
329
|
+
readonly [DependencyIds]?: readonly symbol[];
|
|
314
330
|
/**
|
|
315
331
|
* Parses the input using the actual dependency value instead of the default.
|
|
316
332
|
* This method is used during dependency resolution in `complete()`.
|
|
@@ -460,9 +476,14 @@ interface DeferredParseState<T = unknown> {
|
|
|
460
476
|
*/
|
|
461
477
|
readonly parser: DerivedValueParser<Mode, T, unknown>;
|
|
462
478
|
/**
|
|
463
|
-
* The dependency ID that this parser depends on.
|
|
479
|
+
* The dependency ID that this parser depends on (for single-dependency parsers).
|
|
464
480
|
*/
|
|
465
481
|
readonly dependencyId: symbol;
|
|
482
|
+
/**
|
|
483
|
+
* The dependency IDs that this parser depends on (for multi-dependency parsers).
|
|
484
|
+
* If present, this is used instead of `dependencyId`.
|
|
485
|
+
*/
|
|
486
|
+
readonly dependencyIds?: readonly symbol[];
|
|
466
487
|
/**
|
|
467
488
|
* The preliminary parse result using the default dependency value.
|
|
468
489
|
* This is used as a fallback if dependency resolution is not needed
|
|
@@ -535,6 +556,62 @@ declare function isDependencySourceState<T>(value: unknown): value is Dependency
|
|
|
535
556
|
* @since 0.10.0
|
|
536
557
|
*/
|
|
537
558
|
declare function createDependencySourceState<T>(result: ValueParserResult<T>, dependencyId: symbol): DependencySourceState<T>;
|
|
559
|
+
/**
|
|
560
|
+
* A unique symbol used to identify pending dependency source states.
|
|
561
|
+
* @since 0.10.0
|
|
562
|
+
*/
|
|
563
|
+
declare const PendingDependencySourceStateMarker: unique symbol;
|
|
564
|
+
/**
|
|
565
|
+
* Represents a pending dependency source state.
|
|
566
|
+
* This is used when a dependency source option was not provided, but its
|
|
567
|
+
* dependency ID still needs to be tracked for later resolution with a
|
|
568
|
+
* default value.
|
|
569
|
+
*
|
|
570
|
+
* @since 0.10.0
|
|
571
|
+
*/
|
|
572
|
+
interface PendingDependencySourceState {
|
|
573
|
+
/**
|
|
574
|
+
* Marker to identify this as a pending dependency source state.
|
|
575
|
+
*/
|
|
576
|
+
readonly [PendingDependencySourceStateMarker]: true;
|
|
577
|
+
/**
|
|
578
|
+
* The dependency ID of the source.
|
|
579
|
+
*/
|
|
580
|
+
readonly [DependencyId]: symbol;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Checks if a value is a {@link PendingDependencySourceState}.
|
|
584
|
+
*
|
|
585
|
+
* @param value The value to check.
|
|
586
|
+
* @returns `true` if the value is a pending dependency source state.
|
|
587
|
+
* @since 0.10.0
|
|
588
|
+
*/
|
|
589
|
+
declare function isPendingDependencySourceState(value: unknown): value is PendingDependencySourceState;
|
|
590
|
+
/**
|
|
591
|
+
* Creates a pending dependency source state.
|
|
592
|
+
*
|
|
593
|
+
* @param dependencyId The dependency ID.
|
|
594
|
+
* @returns A PendingDependencySourceState object.
|
|
595
|
+
* @since 0.10.0
|
|
596
|
+
*/
|
|
597
|
+
declare function createPendingDependencySourceState(dependencyId: symbol): PendingDependencySourceState;
|
|
598
|
+
/**
|
|
599
|
+
* A unique symbol used to identify parsers that wrap a dependency source.
|
|
600
|
+
* This is used by withDefault to indicate it contains an inner parser
|
|
601
|
+
* with a PendingDependencySourceState initialState.
|
|
602
|
+
* @since 0.10.0
|
|
603
|
+
*/
|
|
604
|
+
declare const WrappedDependencySourceMarker: unique symbol;
|
|
605
|
+
/**
|
|
606
|
+
* Checks if a parser wraps a dependency source (has WrappedDependencySourceMarker).
|
|
607
|
+
*
|
|
608
|
+
* @param parser The parser to check.
|
|
609
|
+
* @returns `true` if the parser wraps a dependency source.
|
|
610
|
+
* @since 0.10.0
|
|
611
|
+
*/
|
|
612
|
+
declare function isWrappedDependencySource(parser: unknown): parser is {
|
|
613
|
+
[WrappedDependencySourceMarker]: PendingDependencySourceState;
|
|
614
|
+
};
|
|
538
615
|
/**
|
|
539
616
|
* Represents a resolved dependency value stored during parsing.
|
|
540
617
|
* @since 0.10.0
|
|
@@ -614,4 +691,4 @@ type DependencyError = {
|
|
|
614
691
|
*/
|
|
615
692
|
declare function formatDependencyError(error: DependencyError): Message;
|
|
616
693
|
//#endregion
|
|
617
|
-
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
|
694
|
+
export { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource };
|
package/dist/dependency.js
CHANGED
|
@@ -19,6 +19,12 @@ const DerivedValueParserMarker = Symbol.for("@optique/core/dependency/DerivedVal
|
|
|
19
19
|
*/
|
|
20
20
|
const DependencyId = Symbol.for("@optique/core/dependency/DependencyId");
|
|
21
21
|
/**
|
|
22
|
+
* A unique symbol used to store multiple dependency IDs on derived parsers
|
|
23
|
+
* that depend on multiple sources (created via {@link deriveFrom}).
|
|
24
|
+
* @since 0.10.0
|
|
25
|
+
*/
|
|
26
|
+
const DependencyIds = Symbol.for("@optique/core/dependency/DependencyIds");
|
|
27
|
+
/**
|
|
22
28
|
* A unique symbol used to access the parseWithDependency method on derived parsers.
|
|
23
29
|
* @since 0.10.0
|
|
24
30
|
*/
|
|
@@ -180,11 +186,13 @@ function determineFactoryModeForDeriveFrom(options) {
|
|
|
180
186
|
return parser.$mode === "async";
|
|
181
187
|
}
|
|
182
188
|
function createSyncDerivedFromParser(sourceId, options) {
|
|
189
|
+
const allDependencyIds = options.dependencies.map((dep) => dep[DependencyId]);
|
|
183
190
|
return {
|
|
184
191
|
$mode: "sync",
|
|
185
192
|
metavar: options.metavar,
|
|
186
193
|
[DerivedValueParserMarker]: true,
|
|
187
194
|
[DependencyId]: sourceId,
|
|
195
|
+
[DependencyIds]: allDependencyIds,
|
|
188
196
|
parse(input) {
|
|
189
197
|
const sourceValues = options.defaultValues();
|
|
190
198
|
const derivedParser = options.factory(...sourceValues);
|
|
@@ -211,11 +219,13 @@ function createSyncDerivedFromParser(sourceId, options) {
|
|
|
211
219
|
* factory returns an async parser.
|
|
212
220
|
*/
|
|
213
221
|
function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
|
|
222
|
+
const allDependencyIds = options.dependencies.map((dep) => dep[DependencyId]);
|
|
214
223
|
return {
|
|
215
224
|
$mode: "async",
|
|
216
225
|
metavar: options.metavar,
|
|
217
226
|
[DerivedValueParserMarker]: true,
|
|
218
227
|
[DependencyId]: sourceId,
|
|
228
|
+
[DependencyIds]: allDependencyIds,
|
|
219
229
|
parse(input) {
|
|
220
230
|
const sourceValues = options.defaultValues();
|
|
221
231
|
const derivedParser = options.factory(...sourceValues);
|
|
@@ -242,11 +252,13 @@ function createAsyncDerivedFromParserFromAsyncFactory(sourceId, options) {
|
|
|
242
252
|
* sources are async but the factory returns a sync parser.
|
|
243
253
|
*/
|
|
244
254
|
function createAsyncDerivedFromParserFromSyncFactory(sourceId, options) {
|
|
255
|
+
const allDependencyIds = options.dependencies.map((dep) => dep[DependencyId]);
|
|
245
256
|
return {
|
|
246
257
|
$mode: "async",
|
|
247
258
|
metavar: options.metavar,
|
|
248
259
|
[DerivedValueParserMarker]: true,
|
|
249
260
|
[DependencyId]: sourceId,
|
|
261
|
+
[DependencyIds]: allDependencyIds,
|
|
250
262
|
parse(input) {
|
|
251
263
|
const sourceValues = options.defaultValues();
|
|
252
264
|
const derivedParser = options.factory(...sourceValues);
|
|
@@ -402,11 +414,13 @@ function isDeferredParseState(value) {
|
|
|
402
414
|
* @since 0.10.0
|
|
403
415
|
*/
|
|
404
416
|
function createDeferredParseState(rawInput, parser, preliminaryResult) {
|
|
417
|
+
const multipleIds = DependencyIds in parser ? parser[DependencyIds] : void 0;
|
|
405
418
|
return {
|
|
406
419
|
[DeferredParseMarker]: true,
|
|
407
420
|
rawInput,
|
|
408
421
|
parser,
|
|
409
422
|
dependencyId: parser[DependencyId],
|
|
423
|
+
dependencyIds: multipleIds,
|
|
410
424
|
preliminaryResult
|
|
411
425
|
};
|
|
412
426
|
}
|
|
@@ -442,6 +456,51 @@ function createDependencySourceState(result, dependencyId) {
|
|
|
442
456
|
};
|
|
443
457
|
}
|
|
444
458
|
/**
|
|
459
|
+
* A unique symbol used to identify pending dependency source states.
|
|
460
|
+
* @since 0.10.0
|
|
461
|
+
*/
|
|
462
|
+
const PendingDependencySourceStateMarker = Symbol.for("@optique/core/dependency/PendingDependencySourceStateMarker");
|
|
463
|
+
/**
|
|
464
|
+
* Checks if a value is a {@link PendingDependencySourceState}.
|
|
465
|
+
*
|
|
466
|
+
* @param value The value to check.
|
|
467
|
+
* @returns `true` if the value is a pending dependency source state.
|
|
468
|
+
* @since 0.10.0
|
|
469
|
+
*/
|
|
470
|
+
function isPendingDependencySourceState(value) {
|
|
471
|
+
return typeof value === "object" && value !== null && PendingDependencySourceStateMarker in value && value[PendingDependencySourceStateMarker] === true;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Creates a pending dependency source state.
|
|
475
|
+
*
|
|
476
|
+
* @param dependencyId The dependency ID.
|
|
477
|
+
* @returns A PendingDependencySourceState object.
|
|
478
|
+
* @since 0.10.0
|
|
479
|
+
*/
|
|
480
|
+
function createPendingDependencySourceState(dependencyId) {
|
|
481
|
+
return {
|
|
482
|
+
[PendingDependencySourceStateMarker]: true,
|
|
483
|
+
[DependencyId]: dependencyId
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* A unique symbol used to identify parsers that wrap a dependency source.
|
|
488
|
+
* This is used by withDefault to indicate it contains an inner parser
|
|
489
|
+
* with a PendingDependencySourceState initialState.
|
|
490
|
+
* @since 0.10.0
|
|
491
|
+
*/
|
|
492
|
+
const WrappedDependencySourceMarker = Symbol.for("@optique/core/dependency/WrappedDependencySourceMarker");
|
|
493
|
+
/**
|
|
494
|
+
* Checks if a parser wraps a dependency source (has WrappedDependencySourceMarker).
|
|
495
|
+
*
|
|
496
|
+
* @param parser The parser to check.
|
|
497
|
+
* @returns `true` if the parser wraps a dependency source.
|
|
498
|
+
* @since 0.10.0
|
|
499
|
+
*/
|
|
500
|
+
function isWrappedDependencySource(parser) {
|
|
501
|
+
return typeof parser === "object" && parser !== null && WrappedDependencySourceMarker in parser;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
445
504
|
* A registry for storing resolved dependency values during parsing.
|
|
446
505
|
* This is used to pass dependency values from DependencySource options
|
|
447
506
|
* to DerivedValueParser options.
|
|
@@ -507,4 +566,4 @@ function formatDependencyError(error) {
|
|
|
507
566
|
}
|
|
508
567
|
|
|
509
568
|
//#endregion
|
|
510
|
-
export { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser };
|
|
569
|
+
export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceStateMarker, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource };
|
package/dist/index.cjs
CHANGED
|
@@ -13,15 +13,18 @@ const require_facade = require('./facade.cjs');
|
|
|
13
13
|
|
|
14
14
|
exports.DeferredParseMarker = require_dependency.DeferredParseMarker;
|
|
15
15
|
exports.DependencyId = require_dependency.DependencyId;
|
|
16
|
+
exports.DependencyIds = require_dependency.DependencyIds;
|
|
16
17
|
exports.DependencyRegistry = require_dependency.DependencyRegistry;
|
|
17
18
|
exports.DependencySourceMarker = require_dependency.DependencySourceMarker;
|
|
18
19
|
exports.DependencySourceStateMarker = require_dependency.DependencySourceStateMarker;
|
|
19
20
|
exports.DerivedValueParserMarker = require_dependency.DerivedValueParserMarker;
|
|
20
21
|
exports.DuplicateOptionError = require_constructs.DuplicateOptionError;
|
|
21
22
|
exports.ParseWithDependency = require_dependency.ParseWithDependency;
|
|
23
|
+
exports.PendingDependencySourceStateMarker = require_dependency.PendingDependencySourceStateMarker;
|
|
22
24
|
exports.RunError = require_facade.RunError;
|
|
23
25
|
exports.RunParserError = require_facade.RunParserError;
|
|
24
26
|
exports.WithDefaultError = require_modifiers.WithDefaultError;
|
|
27
|
+
exports.WrappedDependencySourceMarker = require_dependency.WrappedDependencySourceMarker;
|
|
25
28
|
exports.argument = require_primitives.argument;
|
|
26
29
|
exports.bash = require_completion.bash;
|
|
27
30
|
exports.choice = require_valueparser.choice;
|
|
@@ -32,6 +35,7 @@ exports.conditional = require_constructs.conditional;
|
|
|
32
35
|
exports.constant = require_primitives.constant;
|
|
33
36
|
exports.createDeferredParseState = require_dependency.createDeferredParseState;
|
|
34
37
|
exports.createDependencySourceState = require_dependency.createDependencySourceState;
|
|
38
|
+
exports.createPendingDependencySourceState = require_dependency.createPendingDependencySourceState;
|
|
35
39
|
exports.dependency = require_dependency.dependency;
|
|
36
40
|
exports.deriveFrom = require_dependency.deriveFrom;
|
|
37
41
|
exports.deriveFromAsync = require_dependency.deriveFromAsync;
|
|
@@ -59,7 +63,9 @@ exports.isDependencySource = require_dependency.isDependencySource;
|
|
|
59
63
|
exports.isDependencySourceState = require_dependency.isDependencySourceState;
|
|
60
64
|
exports.isDerivedValueParser = require_dependency.isDerivedValueParser;
|
|
61
65
|
exports.isNonEmptyString = require_nonempty.isNonEmptyString;
|
|
66
|
+
exports.isPendingDependencySourceState = require_dependency.isPendingDependencySourceState;
|
|
62
67
|
exports.isValueParser = require_valueparser.isValueParser;
|
|
68
|
+
exports.isWrappedDependencySource = require_dependency.isWrappedDependencySource;
|
|
63
69
|
exports.locale = require_valueparser.locale;
|
|
64
70
|
exports.longestMatch = require_constructs.longestMatch;
|
|
65
71
|
exports.map = require_modifiers.map;
|
package/dist/index.d.cts
CHANGED
|
@@ -5,9 +5,9 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
|
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
|
|
6
6
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
|
|
7
7
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.cjs";
|
|
8
|
-
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.cjs";
|
|
8
|
+
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource } from "./dependency.cjs";
|
|
9
9
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
|
|
10
10
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.cjs";
|
|
11
11
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
12
12
|
import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.cjs";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, Doc
|
|
|
5
5
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
|
|
6
6
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
7
7
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, optional, withDefault } from "./modifiers.js";
|
|
8
|
-
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, ResolvedDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
|
|
8
|
+
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource } from "./dependency.js";
|
|
9
9
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
|
|
10
10
|
import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
11
11
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
12
12
|
import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseMarker, DeferredParseState, DependencyError, DependencyId, DependencyIds, DependencyMode, DependencyRegistry, DependencySource, DependencySourceMarker, DependencySourceState, DependencySourceStateMarker, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DerivedValueParserMarker, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, ParseWithDependency, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PendingDependencySourceStateMarker, ResolvedDependency, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
2
2
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
3
|
-
import { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
|
|
3
|
+
import { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, ParseWithDependency, PendingDependencySourceStateMarker, WrappedDependencySourceMarker, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource } from "./dependency.js";
|
|
4
4
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
|
|
5
5
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
6
6
|
import { formatDocPage } from "./doc.js";
|
|
@@ -11,4 +11,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
|
|
|
11
11
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
12
12
|
import { RunError, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
13
|
|
|
14
|
-
export { DeferredParseMarker, DependencyId, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
14
|
+
export { DeferredParseMarker, DependencyId, DependencyIds, DependencyRegistry, DependencySourceMarker, DependencySourceStateMarker, DerivedValueParserMarker, DuplicateOptionError, ParseWithDependency, PendingDependencySourceStateMarker, RunError, RunParserError, WithDefaultError, WrappedDependencySourceMarker, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependency, deriveFrom, deriveFromAsync, deriveFromSync, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/modifiers.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_message = require('./message.cjs');
|
|
2
|
+
const require_dependency = require('./dependency.cjs');
|
|
2
3
|
|
|
3
4
|
//#region src/modifiers.ts
|
|
4
5
|
/**
|
|
@@ -176,6 +177,8 @@ function withDefault(parser, defaultValue, options) {
|
|
|
176
177
|
}, prefix);
|
|
177
178
|
for await (const s of suggestions) yield s;
|
|
178
179
|
}
|
|
180
|
+
const innerInitialState = syncParser.initialState;
|
|
181
|
+
const wrappedDependencyMarker = require_dependency.isPendingDependencySourceState(innerInitialState) ? { [require_dependency.WrappedDependencySourceMarker]: innerInitialState } : {};
|
|
179
182
|
return {
|
|
180
183
|
$mode: parser.$mode,
|
|
181
184
|
$valueType: [],
|
|
@@ -186,6 +189,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
186
189
|
terms: parser.usage
|
|
187
190
|
}],
|
|
188
191
|
initialState: void 0,
|
|
192
|
+
...wrappedDependencyMarker,
|
|
189
193
|
parse(context) {
|
|
190
194
|
if (isAsync) return parseOptionalStyleAsync(context, parser);
|
|
191
195
|
return parseOptionalStyleSync(context, syncParser);
|
|
@@ -203,6 +207,18 @@ function withDefault(parser, defaultValue, options) {
|
|
|
203
207
|
error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
|
|
204
208
|
};
|
|
205
209
|
}
|
|
210
|
+
if (require_dependency.isPendingDependencySourceState(state[0])) try {
|
|
211
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
212
|
+
return require_dependency.createDependencySourceState({
|
|
213
|
+
success: true,
|
|
214
|
+
value
|
|
215
|
+
}, state[0][require_dependency.DependencyId]);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
error: error instanceof WithDefaultError ? error.errorMessage : require_message.message`${require_message.text(String(error))}`
|
|
220
|
+
};
|
|
221
|
+
}
|
|
206
222
|
if (!isAsync) return syncParser.complete(state[0]);
|
|
207
223
|
return parser.complete(state[0]);
|
|
208
224
|
},
|
package/dist/modifiers.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatMessage, message, text } from "./message.js";
|
|
2
|
+
import { DependencyId, WrappedDependencySourceMarker, createDependencySourceState, isPendingDependencySourceState } from "./dependency.js";
|
|
2
3
|
|
|
3
4
|
//#region src/modifiers.ts
|
|
4
5
|
/**
|
|
@@ -176,6 +177,8 @@ function withDefault(parser, defaultValue, options) {
|
|
|
176
177
|
}, prefix);
|
|
177
178
|
for await (const s of suggestions) yield s;
|
|
178
179
|
}
|
|
180
|
+
const innerInitialState = syncParser.initialState;
|
|
181
|
+
const wrappedDependencyMarker = isPendingDependencySourceState(innerInitialState) ? { [WrappedDependencySourceMarker]: innerInitialState } : {};
|
|
179
182
|
return {
|
|
180
183
|
$mode: parser.$mode,
|
|
181
184
|
$valueType: [],
|
|
@@ -186,6 +189,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
186
189
|
terms: parser.usage
|
|
187
190
|
}],
|
|
188
191
|
initialState: void 0,
|
|
192
|
+
...wrappedDependencyMarker,
|
|
189
193
|
parse(context) {
|
|
190
194
|
if (isAsync) return parseOptionalStyleAsync(context, parser);
|
|
191
195
|
return parseOptionalStyleSync(context, syncParser);
|
|
@@ -203,6 +207,18 @@ function withDefault(parser, defaultValue, options) {
|
|
|
203
207
|
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
204
208
|
};
|
|
205
209
|
}
|
|
210
|
+
if (isPendingDependencySourceState(state[0])) try {
|
|
211
|
+
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
212
|
+
return createDependencySourceState({
|
|
213
|
+
success: true,
|
|
214
|
+
value
|
|
215
|
+
}, state[0][DependencyId]);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
error: error instanceof WithDefaultError ? error.errorMessage : message`${text(String(error))}`
|
|
220
|
+
};
|
|
221
|
+
}
|
|
206
222
|
if (!isAsync) return syncParser.complete(state[0]);
|
|
207
223
|
return parser.complete(state[0]);
|
|
208
224
|
},
|
package/dist/primitives.cjs
CHANGED
|
@@ -203,7 +203,7 @@ function option(...args) {
|
|
|
203
203
|
initialState: valueParser == null ? {
|
|
204
204
|
success: true,
|
|
205
205
|
value: false
|
|
206
|
-
} : {
|
|
206
|
+
} : require_dependency.isDependencySource(valueParser) ? require_dependency.createPendingDependencySourceState(valueParser[require_dependency.DependencyId]) : {
|
|
207
207
|
success: false,
|
|
208
208
|
error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
|
|
209
209
|
},
|
|
@@ -229,7 +229,8 @@ function option(...args) {
|
|
|
229
229
|
consumed: context.buffer.slice(0, 1)
|
|
230
230
|
};
|
|
231
231
|
if (optionNames$1.includes(context.buffer[0])) {
|
|
232
|
-
|
|
232
|
+
const hasValue = valueParser != null ? context.state?.success || require_dependency.isDeferredParseState(context.state) || require_dependency.isDependencySourceState(context.state) : context.state?.success && context.state?.value;
|
|
233
|
+
if (hasValue) return {
|
|
233
234
|
success: false,
|
|
234
235
|
consumed: 1,
|
|
235
236
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : require_message.message`${require_message.optionName(context.buffer[0])} cannot be used multiple times.`
|
|
@@ -356,6 +357,10 @@ function option(...args) {
|
|
|
356
357
|
success: false,
|
|
357
358
|
error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
|
|
358
359
|
};
|
|
360
|
+
if (require_dependency.isPendingDependencySourceState(state)) return {
|
|
361
|
+
success: false,
|
|
362
|
+
error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : require_message.message`Missing option ${require_message.optionNames(optionNames$1)}.`
|
|
363
|
+
};
|
|
359
364
|
if (require_dependency.isDeferredParseState(state)) {
|
|
360
365
|
const preliminaryResult = state.preliminaryResult;
|
|
361
366
|
if (preliminaryResult.success) return preliminaryResult;
|
package/dist/primitives.d.cts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Message } from "./message.cjs";
|
|
2
2
|
import { OptionName } from "./usage.cjs";
|
|
3
3
|
import { ValueParser, ValueParserResult } from "./valueparser.cjs";
|
|
4
|
-
import { DeferredParseState } from "./dependency.cjs";
|
|
4
|
+
import { DeferredParseState, PendingDependencySourceState } from "./dependency.cjs";
|
|
5
5
|
import { Mode, Parser } from "./parser.cjs";
|
|
6
6
|
|
|
7
7
|
//#region src/primitives.d.ts
|
|
8
8
|
/**
|
|
9
9
|
* State type for options that may use deferred parsing (DerivedValueParser).
|
|
10
|
-
* This extends the normal ValueParserResult to also support DeferredParseState
|
|
10
|
+
* This extends the normal ValueParserResult to also support DeferredParseState
|
|
11
|
+
* and PendingDependencySourceState.
|
|
11
12
|
* @internal
|
|
12
13
|
*/
|
|
13
|
-
type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | undefined;
|
|
14
|
+
type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDependencySourceState | undefined;
|
|
14
15
|
/**
|
|
15
16
|
* Creates a parser that always succeeds without consuming any input and
|
|
16
17
|
* produces a constant value of the type {@link T}.
|
package/dist/primitives.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Message } from "./message.js";
|
|
2
2
|
import { OptionName } from "./usage.js";
|
|
3
3
|
import { ValueParser, ValueParserResult } from "./valueparser.js";
|
|
4
|
-
import { DeferredParseState } from "./dependency.js";
|
|
4
|
+
import { DeferredParseState, PendingDependencySourceState } from "./dependency.js";
|
|
5
5
|
import { Mode, Parser } from "./parser.js";
|
|
6
6
|
|
|
7
7
|
//#region src/primitives.d.ts
|
|
8
8
|
/**
|
|
9
9
|
* State type for options that may use deferred parsing (DerivedValueParser).
|
|
10
|
-
* This extends the normal ValueParserResult to also support DeferredParseState
|
|
10
|
+
* This extends the normal ValueParserResult to also support DeferredParseState
|
|
11
|
+
* and PendingDependencySourceState.
|
|
11
12
|
* @internal
|
|
12
13
|
*/
|
|
13
|
-
type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | undefined;
|
|
14
|
+
type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDependencySourceState | undefined;
|
|
14
15
|
/**
|
|
15
16
|
* Creates a parser that always succeeds without consuming any input and
|
|
16
17
|
* produces a constant value of the type {@link T}.
|
package/dist/primitives.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { message, metavar, optionName, optionNames } from "./message.js";
|
|
2
|
-
import { DependencyId, createDeferredParseState, createDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser } from "./dependency.js";
|
|
2
|
+
import { DependencyId, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState } from "./dependency.js";
|
|
3
3
|
import { extractCommandNames, extractOptionNames } from "./usage.js";
|
|
4
4
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, findSimilar } from "./suggestion.js";
|
|
5
5
|
import { isValueParser } from "./valueparser.js";
|
|
@@ -203,7 +203,7 @@ function option(...args) {
|
|
|
203
203
|
initialState: valueParser == null ? {
|
|
204
204
|
success: true,
|
|
205
205
|
value: false
|
|
206
|
-
} : {
|
|
206
|
+
} : isDependencySource(valueParser) ? createPendingDependencySourceState(valueParser[DependencyId]) : {
|
|
207
207
|
success: false,
|
|
208
208
|
error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
|
|
209
209
|
},
|
|
@@ -229,7 +229,8 @@ function option(...args) {
|
|
|
229
229
|
consumed: context.buffer.slice(0, 1)
|
|
230
230
|
};
|
|
231
231
|
if (optionNames$1.includes(context.buffer[0])) {
|
|
232
|
-
|
|
232
|
+
const hasValue = valueParser != null ? context.state?.success || isDeferredParseState(context.state) || isDependencySourceState(context.state) : context.state?.success && context.state?.value;
|
|
233
|
+
if (hasValue) return {
|
|
233
234
|
success: false,
|
|
234
235
|
consumed: 1,
|
|
235
236
|
error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : message`${optionName(context.buffer[0])} cannot be used multiple times.`
|
|
@@ -356,6 +357,10 @@ function option(...args) {
|
|
|
356
357
|
success: false,
|
|
357
358
|
error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
|
|
358
359
|
};
|
|
360
|
+
if (isPendingDependencySourceState(state)) return {
|
|
361
|
+
success: false,
|
|
362
|
+
error: options.errors?.missing ? typeof options.errors.missing === "function" ? options.errors.missing(optionNames$1) : options.errors.missing : message`Missing option ${optionNames(optionNames$1)}.`
|
|
363
|
+
};
|
|
359
364
|
if (isDeferredParseState(state)) {
|
|
360
365
|
const preliminaryResult = state.preliminaryResult;
|
|
361
366
|
if (preliminaryResult.success) return preliminaryResult;
|