@optique/core 0.10.0-dev.319 → 0.10.0-dev.324
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 +39 -52
- package/dist/constructs.js +39 -52
- package/dist/dependency.cjs +31 -0
- package/dist/dependency.d.cts +26 -2
- package/dist/dependency.d.ts +26 -2
- package/dist/dependency.js +30 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/mode-dispatch.cjs +38 -0
- package/dist/mode-dispatch.js +36 -0
- package/dist/modifiers.cjs +23 -42
- package/dist/modifiers.js +23 -42
- package/dist/parser.d.cts +2 -3
- package/dist/parser.d.ts +2 -3
- package/dist/primitives.cjs +25 -12
- package/dist/primitives.js +26 -13
- package/dist/registry-types.d.cts +38 -0
- package/dist/registry-types.d.ts +38 -0
- package/package.json +1 -1
package/dist/dependency.js
CHANGED
|
@@ -531,6 +531,35 @@ function isDeferredParseState(value) {
|
|
|
531
531
|
return typeof value === "object" && value !== null && deferredParseMarker in value && value[deferredParseMarker] === true;
|
|
532
532
|
}
|
|
533
533
|
/**
|
|
534
|
+
* Gets all dependency IDs from a derived parser.
|
|
535
|
+
* If the parser was created with `deriveFrom` (multiple dependencies),
|
|
536
|
+
* returns the array of dependency IDs. Otherwise, returns an array
|
|
537
|
+
* containing the single dependency ID.
|
|
538
|
+
*
|
|
539
|
+
* @param parser The derived value parser to get dependency IDs from.
|
|
540
|
+
* @returns An array of dependency ID symbols.
|
|
541
|
+
* @internal
|
|
542
|
+
* @since 0.10.0
|
|
543
|
+
*/
|
|
544
|
+
function getDependencyIds(parser) {
|
|
545
|
+
if (dependencyIds in parser) return parser[dependencyIds];
|
|
546
|
+
return [parser[dependencyId]];
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Gets the default values function from a derived parser, if present.
|
|
550
|
+
* This function is available on parsers created with `deriveFrom` that
|
|
551
|
+
* specify default values for their dependencies.
|
|
552
|
+
*
|
|
553
|
+
* @param parser The derived value parser to get the default values function from.
|
|
554
|
+
* @returns The default values function, or undefined if not available.
|
|
555
|
+
* @internal
|
|
556
|
+
* @since 0.10.0
|
|
557
|
+
*/
|
|
558
|
+
function getDefaultValuesFunction(parser) {
|
|
559
|
+
if (defaultValues in parser) return parser[defaultValues];
|
|
560
|
+
return void 0;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
534
563
|
* Creates a deferred parse state for a DerivedValueParser.
|
|
535
564
|
*
|
|
536
565
|
* @template T The type of value the parser will produce.
|
|
@@ -719,4 +748,4 @@ function formatDependencyError(error) {
|
|
|
719
748
|
}
|
|
720
749
|
|
|
721
750
|
//#endregion
|
|
722
|
-
export { DependencyRegistry, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker };
|
|
751
|
+
export { DependencyRegistry, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker };
|
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,8 @@ exports.formatDocPage = require_doc.formatDocPage;
|
|
|
50
50
|
exports.formatMessage = require_message.formatMessage;
|
|
51
51
|
exports.formatUsage = require_usage.formatUsage;
|
|
52
52
|
exports.formatUsageTerm = require_usage.formatUsageTerm;
|
|
53
|
+
exports.getDefaultValuesFunction = require_dependency.getDefaultValuesFunction;
|
|
54
|
+
exports.getDependencyIds = require_dependency.getDependencyIds;
|
|
53
55
|
exports.getDocPage = require_parser.getDocPage;
|
|
54
56
|
exports.getDocPageAsync = require_parser.getDocPageAsync;
|
|
55
57
|
exports.getDocPageSync = require_parser.getDocPageSync;
|
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, nonEmpty, optional, withDefault } from "./modifiers.cjs";
|
|
8
|
-
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.cjs";
|
|
8
|
+
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } 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 { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.cjs";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, 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, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, 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, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, 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, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, 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, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, 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, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, 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, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
8
|
-
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
8
|
+
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } 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 { RunOptions, RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
|
-
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, 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, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, 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, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, 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, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
13
|
+
export { AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, 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, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, ResolvedDependency, Result, 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, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, 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 { DependencyRegistry, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
3
|
+
import { DependencyRegistry, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } 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 { RunParserError, runParser, runParserAsync, runParserSync } from "./facade.js";
|
|
13
13
|
|
|
14
|
-
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, 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, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
14
|
+
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, locale, longestMatch, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, pwsh, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mode-dispatch.ts
|
|
3
|
+
/**
|
|
4
|
+
* Dispatches to sync or async implementation based on mode.
|
|
5
|
+
*
|
|
6
|
+
* This function encapsulates the necessary type assertions when branching
|
|
7
|
+
* on runtime mode values. TypeScript cannot narrow `ModeValue<M, T>` based
|
|
8
|
+
* on `mode === "async"` checks, so we must use type assertions.
|
|
9
|
+
*
|
|
10
|
+
* @param mode The execution mode.
|
|
11
|
+
* @param syncFn Function to call for sync execution.
|
|
12
|
+
* @param asyncFn Function to call for async execution.
|
|
13
|
+
* @returns The result with correct mode wrapping.
|
|
14
|
+
* @internal
|
|
15
|
+
* @since 0.10.0
|
|
16
|
+
*/
|
|
17
|
+
function dispatchByMode(mode, syncFn, asyncFn) {
|
|
18
|
+
if (mode === "async") return asyncFn();
|
|
19
|
+
return syncFn();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Dispatches iterable to sync or async implementation based on mode.
|
|
23
|
+
*
|
|
24
|
+
* @param mode The execution mode.
|
|
25
|
+
* @param syncFn Function returning sync iterable.
|
|
26
|
+
* @param asyncFn Function returning async iterable.
|
|
27
|
+
* @returns The iterable with correct mode wrapping.
|
|
28
|
+
* @internal
|
|
29
|
+
* @since 0.10.0
|
|
30
|
+
*/
|
|
31
|
+
function dispatchIterableByMode(mode, syncFn, asyncFn) {
|
|
32
|
+
if (mode === "async") return asyncFn();
|
|
33
|
+
return syncFn();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.dispatchByMode = dispatchByMode;
|
|
38
|
+
exports.dispatchIterableByMode = dispatchIterableByMode;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/mode-dispatch.ts
|
|
2
|
+
/**
|
|
3
|
+
* Dispatches to sync or async implementation based on mode.
|
|
4
|
+
*
|
|
5
|
+
* This function encapsulates the necessary type assertions when branching
|
|
6
|
+
* on runtime mode values. TypeScript cannot narrow `ModeValue<M, T>` based
|
|
7
|
+
* on `mode === "async"` checks, so we must use type assertions.
|
|
8
|
+
*
|
|
9
|
+
* @param mode The execution mode.
|
|
10
|
+
* @param syncFn Function to call for sync execution.
|
|
11
|
+
* @param asyncFn Function to call for async execution.
|
|
12
|
+
* @returns The result with correct mode wrapping.
|
|
13
|
+
* @internal
|
|
14
|
+
* @since 0.10.0
|
|
15
|
+
*/
|
|
16
|
+
function dispatchByMode(mode, syncFn, asyncFn) {
|
|
17
|
+
if (mode === "async") return asyncFn();
|
|
18
|
+
return syncFn();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Dispatches iterable to sync or async implementation based on mode.
|
|
22
|
+
*
|
|
23
|
+
* @param mode The execution mode.
|
|
24
|
+
* @param syncFn Function returning sync iterable.
|
|
25
|
+
* @param asyncFn Function returning async iterable.
|
|
26
|
+
* @returns The iterable with correct mode wrapping.
|
|
27
|
+
* @internal
|
|
28
|
+
* @since 0.10.0
|
|
29
|
+
*/
|
|
30
|
+
function dispatchIterableByMode(mode, syncFn, asyncFn) {
|
|
31
|
+
if (mode === "async") return asyncFn();
|
|
32
|
+
return syncFn();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { dispatchByMode, dispatchIterableByMode };
|
package/dist/modifiers.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_message = require('./message.cjs');
|
|
2
2
|
const require_dependency = require('./dependency.cjs');
|
|
3
|
+
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
3
4
|
|
|
4
5
|
//#region src/modifiers.ts
|
|
5
6
|
/**
|
|
@@ -74,7 +75,6 @@ function processOptionalStyleResult(result, innerState, context) {
|
|
|
74
75
|
*/
|
|
75
76
|
function optional(parser) {
|
|
76
77
|
const syncParser = parser;
|
|
77
|
-
const isAsync = parser.$mode === "async";
|
|
78
78
|
function* suggestSync(context, prefix) {
|
|
79
79
|
const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
|
|
80
80
|
yield* syncParser.suggest({
|
|
@@ -107,36 +107,27 @@ function optional(parser) {
|
|
|
107
107
|
initialState: void 0,
|
|
108
108
|
...wrappedDependencyMarker,
|
|
109
109
|
parse(context) {
|
|
110
|
-
|
|
111
|
-
return parseOptionalStyleSync(context, syncParser);
|
|
110
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
112
111
|
},
|
|
113
112
|
complete(state) {
|
|
114
113
|
if (typeof state === "undefined") {
|
|
115
|
-
if (innerHasWrappedDependency && wrappedPendingState)
|
|
116
|
-
if (!isAsync) return syncParser.complete([wrappedPendingState]);
|
|
117
|
-
return parser.complete([wrappedPendingState]);
|
|
118
|
-
}
|
|
114
|
+
if (innerHasWrappedDependency && wrappedPendingState) return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete([wrappedPendingState]), () => parser.complete([wrappedPendingState]));
|
|
119
115
|
return {
|
|
120
116
|
success: true,
|
|
121
117
|
value: void 0
|
|
122
118
|
};
|
|
123
119
|
}
|
|
124
120
|
if (Array.isArray(state) && state.length === 1 && require_dependency.isPendingDependencySourceState(state[0])) {
|
|
125
|
-
if (innerHasWrappedDependency)
|
|
126
|
-
if (!isAsync) return syncParser.complete(state);
|
|
127
|
-
return parser.complete(state);
|
|
128
|
-
}
|
|
121
|
+
if (innerHasWrappedDependency) return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
129
122
|
return {
|
|
130
123
|
success: true,
|
|
131
124
|
value: void 0
|
|
132
125
|
};
|
|
133
126
|
}
|
|
134
|
-
|
|
135
|
-
return parser.complete(state[0]);
|
|
127
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(state[0]), () => parser.complete(state[0]));
|
|
136
128
|
},
|
|
137
129
|
suggest(context, prefix) {
|
|
138
|
-
|
|
139
|
-
return suggestSync(context, prefix);
|
|
130
|
+
return require_mode_dispatch.dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
140
131
|
},
|
|
141
132
|
getDocFragments(state, defaultValue) {
|
|
142
133
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -183,7 +174,6 @@ var WithDefaultError = class extends Error {
|
|
|
183
174
|
};
|
|
184
175
|
function withDefault(parser, defaultValue, options) {
|
|
185
176
|
const syncParser = parser;
|
|
186
|
-
const isAsync = parser.$mode === "async";
|
|
187
177
|
function* suggestSync(context, prefix) {
|
|
188
178
|
const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
|
|
189
179
|
yield* syncParser.suggest({
|
|
@@ -213,13 +203,12 @@ function withDefault(parser, defaultValue, options) {
|
|
|
213
203
|
initialState: void 0,
|
|
214
204
|
...wrappedDependencyMarker,
|
|
215
205
|
parse(context) {
|
|
216
|
-
|
|
217
|
-
return parseOptionalStyleSync(context, syncParser);
|
|
206
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
218
207
|
},
|
|
219
208
|
complete(state) {
|
|
220
209
|
if (typeof state === "undefined") {
|
|
221
210
|
if (require_dependency.transformsDependencyValue(parser)) {
|
|
222
|
-
const innerResult =
|
|
211
|
+
const innerResult = require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(void 0), () => parser.complete(void 0));
|
|
223
212
|
const handleInnerResult = (res) => {
|
|
224
213
|
if (require_dependency.isDependencySourceState(res)) try {
|
|
225
214
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -277,7 +266,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
277
266
|
}
|
|
278
267
|
if (require_dependency.isPendingDependencySourceState(state[0])) {
|
|
279
268
|
if (require_dependency.transformsDependencyValue(parser)) {
|
|
280
|
-
const innerResult =
|
|
269
|
+
const innerResult = require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
281
270
|
const handleInnerResult = (res) => {
|
|
282
271
|
if (require_dependency.isDependencySourceState(res)) try {
|
|
283
272
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -320,12 +309,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
320
309
|
};
|
|
321
310
|
}
|
|
322
311
|
}
|
|
323
|
-
|
|
324
|
-
return parser.complete(state[0]);
|
|
312
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => syncParser.complete(state[0]), () => parser.complete(state[0]));
|
|
325
313
|
},
|
|
326
314
|
suggest(context, prefix) {
|
|
327
|
-
|
|
328
|
-
return suggestSync(context, prefix);
|
|
315
|
+
return require_mode_dispatch.dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
329
316
|
},
|
|
330
317
|
getDocFragments(state, upperDefaultValue) {
|
|
331
318
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -432,7 +419,6 @@ function map(parser, transform) {
|
|
|
432
419
|
*/
|
|
433
420
|
function multiple(parser, options = {}) {
|
|
434
421
|
const syncParser = parser;
|
|
435
|
-
const isAsync = parser.$mode === "async";
|
|
436
422
|
const { min = 0, max = Infinity } = options;
|
|
437
423
|
const parseSync = (context) => {
|
|
438
424
|
let added = context.state.length < 1;
|
|
@@ -494,11 +480,10 @@ function multiple(parser, options = {}) {
|
|
|
494
480
|
}],
|
|
495
481
|
initialState: [],
|
|
496
482
|
parse(context) {
|
|
497
|
-
|
|
498
|
-
return parseSync(context);
|
|
483
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseSync(context), () => parseAsync(context));
|
|
499
484
|
},
|
|
500
485
|
complete(state) {
|
|
501
|
-
|
|
486
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
|
|
502
487
|
const result = [];
|
|
503
488
|
for (const s of state) {
|
|
504
489
|
const valueResult = syncParser.complete(s);
|
|
@@ -509,8 +494,7 @@ function multiple(parser, options = {}) {
|
|
|
509
494
|
};
|
|
510
495
|
}
|
|
511
496
|
return validateMultipleResult(result);
|
|
512
|
-
}
|
|
513
|
-
return (async () => {
|
|
497
|
+
}, async () => {
|
|
514
498
|
const results = await Promise.all(state.map((s) => parser.complete(s)));
|
|
515
499
|
const values = [];
|
|
516
500
|
for (const valueResult of results) if (valueResult.success) values.push(valueResult.value);
|
|
@@ -519,7 +503,7 @@ function multiple(parser, options = {}) {
|
|
|
519
503
|
error: valueResult.error
|
|
520
504
|
};
|
|
521
505
|
return validateMultipleResult(values);
|
|
522
|
-
})
|
|
506
|
+
});
|
|
523
507
|
},
|
|
524
508
|
suggest(context, prefix) {
|
|
525
509
|
const innerState = context.state.length > 0 ? context.state.at(-1) : parser.initialState;
|
|
@@ -535,19 +519,18 @@ function multiple(parser, options = {}) {
|
|
|
535
519
|
if (suggestion.kind === "literal") return !selectedValues.has(suggestion.text);
|
|
536
520
|
return true;
|
|
537
521
|
};
|
|
538
|
-
|
|
522
|
+
return require_mode_dispatch.dispatchIterableByMode(parser.$mode, function* () {
|
|
523
|
+
for (const s of syncParser.suggest({
|
|
524
|
+
...context,
|
|
525
|
+
state: innerState
|
|
526
|
+
}, prefix)) if (shouldInclude(s)) yield s;
|
|
527
|
+
}, async function* () {
|
|
539
528
|
const suggestions = parser.suggest({
|
|
540
529
|
...context,
|
|
541
530
|
state: innerState
|
|
542
531
|
}, prefix);
|
|
543
532
|
for await (const s of suggestions) if (shouldInclude(s)) yield s;
|
|
544
|
-
}
|
|
545
|
-
return function* () {
|
|
546
|
-
for (const s of syncParser.suggest({
|
|
547
|
-
...context,
|
|
548
|
-
state: innerState
|
|
549
|
-
}, prefix)) if (shouldInclude(s)) yield s;
|
|
550
|
-
}();
|
|
533
|
+
});
|
|
551
534
|
},
|
|
552
535
|
getDocFragments(state, defaultValue) {
|
|
553
536
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state.length > 0 ? {
|
|
@@ -617,7 +600,6 @@ function multiple(parser, options = {}) {
|
|
|
617
600
|
*/
|
|
618
601
|
function nonEmpty(parser) {
|
|
619
602
|
const syncParser = parser;
|
|
620
|
-
const isAsync = parser.$mode === "async";
|
|
621
603
|
const processNonEmptyResult = (result) => {
|
|
622
604
|
if (!result.success) return result;
|
|
623
605
|
if (result.consumed.length === 0) return {
|
|
@@ -643,8 +625,7 @@ function nonEmpty(parser) {
|
|
|
643
625
|
usage: parser.usage,
|
|
644
626
|
initialState: parser.initialState,
|
|
645
627
|
parse(context) {
|
|
646
|
-
|
|
647
|
-
return parseSync(context);
|
|
628
|
+
return require_mode_dispatch.dispatchByMode(parser.$mode, () => parseSync(context), () => parseAsync(context));
|
|
648
629
|
},
|
|
649
630
|
complete(state) {
|
|
650
631
|
return parser.complete(state);
|
package/dist/modifiers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { formatMessage, message, text } from "./message.js";
|
|
2
2
|
import { createDependencySourceState, dependencyId, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
|
|
3
|
+
import { dispatchByMode, dispatchIterableByMode } from "./mode-dispatch.js";
|
|
3
4
|
|
|
4
5
|
//#region src/modifiers.ts
|
|
5
6
|
/**
|
|
@@ -74,7 +75,6 @@ function processOptionalStyleResult(result, innerState, context) {
|
|
|
74
75
|
*/
|
|
75
76
|
function optional(parser) {
|
|
76
77
|
const syncParser = parser;
|
|
77
|
-
const isAsync = parser.$mode === "async";
|
|
78
78
|
function* suggestSync(context, prefix) {
|
|
79
79
|
const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
|
|
80
80
|
yield* syncParser.suggest({
|
|
@@ -107,36 +107,27 @@ function optional(parser) {
|
|
|
107
107
|
initialState: void 0,
|
|
108
108
|
...wrappedDependencyMarker,
|
|
109
109
|
parse(context) {
|
|
110
|
-
|
|
111
|
-
return parseOptionalStyleSync(context, syncParser);
|
|
110
|
+
return dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
112
111
|
},
|
|
113
112
|
complete(state) {
|
|
114
113
|
if (typeof state === "undefined") {
|
|
115
|
-
if (innerHasWrappedDependency && wrappedPendingState)
|
|
116
|
-
if (!isAsync) return syncParser.complete([wrappedPendingState]);
|
|
117
|
-
return parser.complete([wrappedPendingState]);
|
|
118
|
-
}
|
|
114
|
+
if (innerHasWrappedDependency && wrappedPendingState) return dispatchByMode(parser.$mode, () => syncParser.complete([wrappedPendingState]), () => parser.complete([wrappedPendingState]));
|
|
119
115
|
return {
|
|
120
116
|
success: true,
|
|
121
117
|
value: void 0
|
|
122
118
|
};
|
|
123
119
|
}
|
|
124
120
|
if (Array.isArray(state) && state.length === 1 && isPendingDependencySourceState(state[0])) {
|
|
125
|
-
if (innerHasWrappedDependency)
|
|
126
|
-
if (!isAsync) return syncParser.complete(state);
|
|
127
|
-
return parser.complete(state);
|
|
128
|
-
}
|
|
121
|
+
if (innerHasWrappedDependency) return dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
129
122
|
return {
|
|
130
123
|
success: true,
|
|
131
124
|
value: void 0
|
|
132
125
|
};
|
|
133
126
|
}
|
|
134
|
-
|
|
135
|
-
return parser.complete(state[0]);
|
|
127
|
+
return dispatchByMode(parser.$mode, () => syncParser.complete(state[0]), () => parser.complete(state[0]));
|
|
136
128
|
},
|
|
137
129
|
suggest(context, prefix) {
|
|
138
|
-
|
|
139
|
-
return suggestSync(context, prefix);
|
|
130
|
+
return dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
140
131
|
},
|
|
141
132
|
getDocFragments(state, defaultValue) {
|
|
142
133
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -183,7 +174,6 @@ var WithDefaultError = class extends Error {
|
|
|
183
174
|
};
|
|
184
175
|
function withDefault(parser, defaultValue, options) {
|
|
185
176
|
const syncParser = parser;
|
|
186
|
-
const isAsync = parser.$mode === "async";
|
|
187
177
|
function* suggestSync(context, prefix) {
|
|
188
178
|
const innerState = typeof context.state === "undefined" ? syncParser.initialState : context.state[0];
|
|
189
179
|
yield* syncParser.suggest({
|
|
@@ -213,13 +203,12 @@ function withDefault(parser, defaultValue, options) {
|
|
|
213
203
|
initialState: void 0,
|
|
214
204
|
...wrappedDependencyMarker,
|
|
215
205
|
parse(context) {
|
|
216
|
-
|
|
217
|
-
return parseOptionalStyleSync(context, syncParser);
|
|
206
|
+
return dispatchByMode(parser.$mode, () => parseOptionalStyleSync(context, syncParser), () => parseOptionalStyleAsync(context, parser));
|
|
218
207
|
},
|
|
219
208
|
complete(state) {
|
|
220
209
|
if (typeof state === "undefined") {
|
|
221
210
|
if (transformsDependencyValue(parser)) {
|
|
222
|
-
const innerResult =
|
|
211
|
+
const innerResult = dispatchByMode(parser.$mode, () => syncParser.complete(void 0), () => parser.complete(void 0));
|
|
223
212
|
const handleInnerResult = (res) => {
|
|
224
213
|
if (isDependencySourceState(res)) try {
|
|
225
214
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -277,7 +266,7 @@ function withDefault(parser, defaultValue, options) {
|
|
|
277
266
|
}
|
|
278
267
|
if (isPendingDependencySourceState(state[0])) {
|
|
279
268
|
if (transformsDependencyValue(parser)) {
|
|
280
|
-
const innerResult =
|
|
269
|
+
const innerResult = dispatchByMode(parser.$mode, () => syncParser.complete(state), () => parser.complete(state));
|
|
281
270
|
const handleInnerResult = (res) => {
|
|
282
271
|
if (isDependencySourceState(res)) try {
|
|
283
272
|
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
@@ -320,12 +309,10 @@ function withDefault(parser, defaultValue, options) {
|
|
|
320
309
|
};
|
|
321
310
|
}
|
|
322
311
|
}
|
|
323
|
-
|
|
324
|
-
return parser.complete(state[0]);
|
|
312
|
+
return dispatchByMode(parser.$mode, () => syncParser.complete(state[0]), () => parser.complete(state[0]));
|
|
325
313
|
},
|
|
326
314
|
suggest(context, prefix) {
|
|
327
|
-
|
|
328
|
-
return suggestSync(context, prefix);
|
|
315
|
+
return dispatchIterableByMode(parser.$mode, () => suggestSync(context, prefix), () => suggestAsync(context, prefix));
|
|
329
316
|
},
|
|
330
317
|
getDocFragments(state, upperDefaultValue) {
|
|
331
318
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state === void 0 ? { kind: "unavailable" } : {
|
|
@@ -432,7 +419,6 @@ function map(parser, transform) {
|
|
|
432
419
|
*/
|
|
433
420
|
function multiple(parser, options = {}) {
|
|
434
421
|
const syncParser = parser;
|
|
435
|
-
const isAsync = parser.$mode === "async";
|
|
436
422
|
const { min = 0, max = Infinity } = options;
|
|
437
423
|
const parseSync = (context) => {
|
|
438
424
|
let added = context.state.length < 1;
|
|
@@ -494,11 +480,10 @@ function multiple(parser, options = {}) {
|
|
|
494
480
|
}],
|
|
495
481
|
initialState: [],
|
|
496
482
|
parse(context) {
|
|
497
|
-
|
|
498
|
-
return parseSync(context);
|
|
483
|
+
return dispatchByMode(parser.$mode, () => parseSync(context), () => parseAsync(context));
|
|
499
484
|
},
|
|
500
485
|
complete(state) {
|
|
501
|
-
|
|
486
|
+
return dispatchByMode(parser.$mode, () => {
|
|
502
487
|
const result = [];
|
|
503
488
|
for (const s of state) {
|
|
504
489
|
const valueResult = syncParser.complete(s);
|
|
@@ -509,8 +494,7 @@ function multiple(parser, options = {}) {
|
|
|
509
494
|
};
|
|
510
495
|
}
|
|
511
496
|
return validateMultipleResult(result);
|
|
512
|
-
}
|
|
513
|
-
return (async () => {
|
|
497
|
+
}, async () => {
|
|
514
498
|
const results = await Promise.all(state.map((s) => parser.complete(s)));
|
|
515
499
|
const values = [];
|
|
516
500
|
for (const valueResult of results) if (valueResult.success) values.push(valueResult.value);
|
|
@@ -519,7 +503,7 @@ function multiple(parser, options = {}) {
|
|
|
519
503
|
error: valueResult.error
|
|
520
504
|
};
|
|
521
505
|
return validateMultipleResult(values);
|
|
522
|
-
})
|
|
506
|
+
});
|
|
523
507
|
},
|
|
524
508
|
suggest(context, prefix) {
|
|
525
509
|
const innerState = context.state.length > 0 ? context.state.at(-1) : parser.initialState;
|
|
@@ -535,19 +519,18 @@ function multiple(parser, options = {}) {
|
|
|
535
519
|
if (suggestion.kind === "literal") return !selectedValues.has(suggestion.text);
|
|
536
520
|
return true;
|
|
537
521
|
};
|
|
538
|
-
|
|
522
|
+
return dispatchIterableByMode(parser.$mode, function* () {
|
|
523
|
+
for (const s of syncParser.suggest({
|
|
524
|
+
...context,
|
|
525
|
+
state: innerState
|
|
526
|
+
}, prefix)) if (shouldInclude(s)) yield s;
|
|
527
|
+
}, async function* () {
|
|
539
528
|
const suggestions = parser.suggest({
|
|
540
529
|
...context,
|
|
541
530
|
state: innerState
|
|
542
531
|
}, prefix);
|
|
543
532
|
for await (const s of suggestions) if (shouldInclude(s)) yield s;
|
|
544
|
-
}
|
|
545
|
-
return function* () {
|
|
546
|
-
for (const s of syncParser.suggest({
|
|
547
|
-
...context,
|
|
548
|
-
state: innerState
|
|
549
|
-
}, prefix)) if (shouldInclude(s)) yield s;
|
|
550
|
-
}();
|
|
533
|
+
});
|
|
551
534
|
},
|
|
552
535
|
getDocFragments(state, defaultValue) {
|
|
553
536
|
const innerState = state.kind === "unavailable" ? { kind: "unavailable" } : state.state.length > 0 ? {
|
|
@@ -617,7 +600,6 @@ function multiple(parser, options = {}) {
|
|
|
617
600
|
*/
|
|
618
601
|
function nonEmpty(parser) {
|
|
619
602
|
const syncParser = parser;
|
|
620
|
-
const isAsync = parser.$mode === "async";
|
|
621
603
|
const processNonEmptyResult = (result) => {
|
|
622
604
|
if (!result.success) return result;
|
|
623
605
|
if (result.consumed.length === 0) return {
|
|
@@ -643,8 +625,7 @@ function nonEmpty(parser) {
|
|
|
643
625
|
usage: parser.usage,
|
|
644
626
|
initialState: parser.initialState,
|
|
645
627
|
parse(context) {
|
|
646
|
-
|
|
647
|
-
return parseSync(context);
|
|
628
|
+
return dispatchByMode(parser.$mode, () => parseSync(context), () => parseAsync(context));
|
|
648
629
|
},
|
|
649
630
|
complete(state) {
|
|
650
631
|
return parser.complete(state);
|
package/dist/parser.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message } from "./message.cjs";
|
|
2
2
|
import { Usage } from "./usage.cjs";
|
|
3
3
|
import { DocFragments, DocPage } from "./doc.cjs";
|
|
4
|
+
import { DependencyRegistryLike } from "./registry-types.cjs";
|
|
4
5
|
import { ValueParserResult } from "./valueparser.cjs";
|
|
5
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";
|
|
6
7
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
|
|
@@ -191,11 +192,9 @@ interface ParserContext<TState> {
|
|
|
191
192
|
* A registry containing resolved dependency values from DependencySource parsers.
|
|
192
193
|
* This is used during shell completion to provide suggestions based on
|
|
193
194
|
* the actual dependency values that have been parsed, rather than defaults.
|
|
194
|
-
* The type is `unknown` to avoid circular dependency issues; the actual type
|
|
195
|
-
* is `DependencyRegistry` from `./dependency.ts`.
|
|
196
195
|
* @since 0.10.0
|
|
197
196
|
*/
|
|
198
|
-
readonly dependencyRegistry?:
|
|
197
|
+
readonly dependencyRegistry?: DependencyRegistryLike;
|
|
199
198
|
}
|
|
200
199
|
/**
|
|
201
200
|
* Represents a suggestion for command-line completion or guidance.
|
package/dist/parser.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message } from "./message.js";
|
|
2
2
|
import { Usage } from "./usage.js";
|
|
3
3
|
import { DocFragments, DocPage } from "./doc.js";
|
|
4
|
+
import { DependencyRegistryLike } from "./registry-types.js";
|
|
4
5
|
import { ValueParserResult } from "./valueparser.js";
|
|
5
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";
|
|
6
7
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
@@ -191,11 +192,9 @@ interface ParserContext<TState> {
|
|
|
191
192
|
* A registry containing resolved dependency values from DependencySource parsers.
|
|
192
193
|
* This is used during shell completion to provide suggestions based on
|
|
193
194
|
* the actual dependency values that have been parsed, rather than defaults.
|
|
194
|
-
* The type is `unknown` to avoid circular dependency issues; the actual type
|
|
195
|
-
* is `DependencyRegistry` from `./dependency.ts`.
|
|
196
195
|
* @since 0.10.0
|
|
197
196
|
*/
|
|
198
|
-
readonly dependencyRegistry?:
|
|
197
|
+
readonly dependencyRegistry?: DependencyRegistryLike;
|
|
199
198
|
}
|
|
200
199
|
/**
|
|
201
200
|
* Represents a suggestion for command-line completion or guidance.
|