@optique/core 1.0.0-dev.1523 → 1.0.0-dev.1533
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 +2 -1
- package/dist/constructs.js +2 -1
- package/dist/facade.cjs +1 -0
- package/dist/facade.js +2 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/parser.cjs +27 -12
- package/dist/parser.d.cts +27 -13
- package/dist/parser.d.ts +27 -13
- package/dist/parser.js +27 -12
- package/dist/usage.cjs +72 -15
- package/dist/usage.d.cts +42 -9
- package/dist/usage.d.ts +42 -9
- package/dist/usage.js +72 -16
- package/dist/validate.cjs +3 -2
- package/dist/validate.js +3 -2
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -2591,7 +2591,8 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
2591
2591
|
result.push(optionWithoutMetavar);
|
|
2592
2592
|
result.push({
|
|
2593
2593
|
type: "literal",
|
|
2594
|
-
value: literalValue
|
|
2594
|
+
value: literalValue,
|
|
2595
|
+
optionValue: true
|
|
2595
2596
|
});
|
|
2596
2597
|
} else if (term.type === "optional") result.push({
|
|
2597
2598
|
...term,
|
package/dist/constructs.js
CHANGED
|
@@ -2591,7 +2591,8 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
2591
2591
|
result.push(optionWithoutMetavar);
|
|
2592
2592
|
result.push({
|
|
2593
2593
|
type: "literal",
|
|
2594
|
-
value: literalValue
|
|
2594
|
+
value: literalValue,
|
|
2595
|
+
optionValue: true
|
|
2595
2596
|
});
|
|
2596
2597
|
} else if (term.type === "optional") result.push({
|
|
2597
2598
|
...term,
|
package/dist/facade.cjs
CHANGED
|
@@ -622,6 +622,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
622
622
|
require_validate.validateMetaNameCollisions({
|
|
623
623
|
leadingOptions: require_usage.extractLeadingOptionNames(parser.usage, true),
|
|
624
624
|
leadingCommands: require_usage.extractLeadingCommandNames(parser.usage, true),
|
|
625
|
+
leadingLiterals: require_usage.extractLeadingLiteralValues(parser.usage),
|
|
625
626
|
allOptions: require_usage.extractOptionNames(parser.usage, true),
|
|
626
627
|
allCommands: require_usage.extractCommandNames(parser.usage, true),
|
|
627
628
|
allLiterals: require_usage.extractLiteralValues(parser.usage)
|
package/dist/facade.js
CHANGED
|
@@ -3,7 +3,7 @@ import { commandLine, formatMessage, lineBreak, message, optionName, text, value
|
|
|
3
3
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
4
4
|
import { dispatchByMode } from "./mode-dispatch.js";
|
|
5
5
|
import { validateCommandNames, validateMetaNameCollisions, validateOptionNames } from "./validate.js";
|
|
6
|
-
import { extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage } from "./usage.js";
|
|
6
|
+
import { extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage } from "./usage.js";
|
|
7
7
|
import { formatDocPage } from "./doc.js";
|
|
8
8
|
import { group, longestMatch, object } from "./constructs.js";
|
|
9
9
|
import { multiple, optional, withDefault } from "./modifiers.js";
|
|
@@ -622,6 +622,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
622
622
|
validateMetaNameCollisions({
|
|
623
623
|
leadingOptions: extractLeadingOptionNames(parser.usage, true),
|
|
624
624
|
leadingCommands: extractLeadingCommandNames(parser.usage, true),
|
|
625
|
+
leadingLiterals: extractLeadingLiteralValues(parser.usage),
|
|
625
626
|
allOptions: extractOptionNames(parser.usage, true),
|
|
626
627
|
allCommands: extractCommandNames(parser.usage, true),
|
|
627
628
|
allLiterals: extractLiteralValues(parser.usage)
|
package/dist/index.cjs
CHANGED
|
@@ -54,6 +54,7 @@ exports.envVar = require_message.envVar;
|
|
|
54
54
|
exports.extractArgumentMetavars = require_usage.extractArgumentMetavars;
|
|
55
55
|
exports.extractCommandNames = require_usage.extractCommandNames;
|
|
56
56
|
exports.extractLeadingCommandNames = require_usage.extractLeadingCommandNames;
|
|
57
|
+
exports.extractLeadingLiteralValues = require_usage.extractLeadingLiteralValues;
|
|
57
58
|
exports.extractLeadingOptionNames = require_usage.extractLeadingOptionNames;
|
|
58
59
|
exports.extractLiteralValues = require_usage.extractLiteralValues;
|
|
59
60
|
exports.extractOptionNames = require_usage.extractOptionNames;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.cjs";
|
|
2
2
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
|
|
3
3
|
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
|
|
4
|
-
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
|
|
4
|
+
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
|
|
5
5
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage, isDocEntryHidden } from "./doc.cjs";
|
|
6
6
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.cjs";
|
|
7
7
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
|
|
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
|
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.cjs";
|
|
14
14
|
import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
15
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
15
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./annotations.js";
|
|
2
2
|
import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
3
3
|
import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
4
|
-
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
4
|
+
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
5
5
|
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage, isDocEntryHidden } from "./doc.js";
|
|
6
6
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
7
7
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
|
|
|
12
12
|
import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
13
13
|
import { ParserValuePlaceholder, SourceContext } from "./context.js";
|
|
14
14
|
import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
15
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { annotationKey, getAnnotations } from "./annotations.js";
|
|
|
2
2
|
import { commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
|
|
3
3
|
import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
4
4
|
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";
|
|
5
|
-
import { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
5
|
+
import { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
6
6
|
import { cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage, isDocEntryHidden } from "./doc.js";
|
|
7
7
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
8
8
|
import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
@@ -12,4 +12,4 @@ import { argument, command, constant, fail, flag, option, passThrough } from "./
|
|
|
12
12
|
import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
|
|
13
13
|
import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
14
14
|
|
|
15
|
-
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
|
15
|
+
export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, deduplicateDocEntries, deduplicateDocFragments, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isPendingDependencySourceState, isSuggestionHidden, isUsageHidden, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
|
package/dist/parser.cjs
CHANGED
|
@@ -299,14 +299,20 @@ function findCommandInExclusive(term, commandName) {
|
|
|
299
299
|
* in a Promise).
|
|
300
300
|
*
|
|
301
301
|
* @param parser The sync parser to generate documentation for.
|
|
302
|
-
* @param
|
|
303
|
-
*
|
|
302
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
303
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
304
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
305
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
306
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
304
307
|
* @returns A {@link DocPage} or `undefined`.
|
|
305
308
|
* @since 0.9.0
|
|
306
309
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
310
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
311
|
+
* directly.
|
|
307
312
|
*/
|
|
308
|
-
function getDocPageSync(parser,
|
|
309
|
-
return getDocPageSyncImpl(parser,
|
|
313
|
+
function getDocPageSync(parser, argsOrOptions, options) {
|
|
314
|
+
if (Array.isArray(argsOrOptions)) return getDocPageSyncImpl(parser, argsOrOptions, options);
|
|
315
|
+
return getDocPageSyncImpl(parser, [], argsOrOptions ?? options);
|
|
310
316
|
}
|
|
311
317
|
/**
|
|
312
318
|
* Generates a documentation page for any parser, returning a Promise.
|
|
@@ -316,19 +322,28 @@ function getDocPageSync(parser, args = [], options) {
|
|
|
316
322
|
* async value parsers.
|
|
317
323
|
*
|
|
318
324
|
* @param parser The parser to generate documentation for.
|
|
319
|
-
* @param
|
|
320
|
-
*
|
|
325
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
326
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
327
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
328
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
329
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
321
330
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
322
331
|
* @since 0.9.0
|
|
323
332
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
333
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
334
|
+
* directly.
|
|
324
335
|
*/
|
|
325
|
-
function getDocPageAsync(parser,
|
|
326
|
-
|
|
327
|
-
|
|
336
|
+
function getDocPageAsync(parser, argsOrOptions, options) {
|
|
337
|
+
const args = Array.isArray(argsOrOptions) ? argsOrOptions : [];
|
|
338
|
+
const opts = Array.isArray(argsOrOptions) ? options : argsOrOptions ?? options;
|
|
339
|
+
if (parser.$mode === "sync") return Promise.resolve(getDocPageSyncImpl(parser, args, opts));
|
|
340
|
+
return getDocPageAsyncImpl(parser, args, opts);
|
|
328
341
|
}
|
|
329
|
-
function getDocPage(parser,
|
|
330
|
-
|
|
331
|
-
|
|
342
|
+
function getDocPage(parser, argsOrOptions, options) {
|
|
343
|
+
const args = Array.isArray(argsOrOptions) ? argsOrOptions : [];
|
|
344
|
+
const opts = Array.isArray(argsOrOptions) ? options : argsOrOptions ?? options;
|
|
345
|
+
if (parser.$mode === "sync") return getDocPageSyncImpl(parser, args, opts);
|
|
346
|
+
return getDocPageAsyncImpl(parser, args, opts);
|
|
332
347
|
}
|
|
333
348
|
/**
|
|
334
349
|
* Internal sync implementation of getDocPage.
|
package/dist/parser.d.cts
CHANGED
|
@@ -511,13 +511,18 @@ declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args:
|
|
|
511
511
|
* in a Promise).
|
|
512
512
|
*
|
|
513
513
|
* @param parser The sync parser to generate documentation for.
|
|
514
|
-
* @param
|
|
515
|
-
*
|
|
514
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
515
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
516
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
517
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
518
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
516
519
|
* @returns A {@link DocPage} or `undefined`.
|
|
517
520
|
* @since 0.9.0
|
|
518
521
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
522
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
523
|
+
* directly.
|
|
519
524
|
*/
|
|
520
|
-
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>,
|
|
525
|
+
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): DocPage | undefined;
|
|
521
526
|
/**
|
|
522
527
|
* Generates a documentation page for any parser, returning a Promise.
|
|
523
528
|
*
|
|
@@ -526,13 +531,18 @@ declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?:
|
|
|
526
531
|
* async value parsers.
|
|
527
532
|
*
|
|
528
533
|
* @param parser The parser to generate documentation for.
|
|
529
|
-
* @param
|
|
530
|
-
*
|
|
534
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
535
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
536
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
537
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
538
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
531
539
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
532
540
|
* @since 0.9.0
|
|
533
541
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
542
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
543
|
+
* directly.
|
|
534
544
|
*/
|
|
535
|
-
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>,
|
|
545
|
+
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
|
|
536
546
|
/**
|
|
537
547
|
* Generates a documentation page for a parser based on its current state after
|
|
538
548
|
* attempting to parse the provided arguments. This function is useful for
|
|
@@ -548,10 +558,12 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
548
558
|
* For async parsers, returns a Promise of the documentation page.
|
|
549
559
|
*
|
|
550
560
|
* @param parser The parser to generate documentation for
|
|
551
|
-
* @param
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
561
|
+
* @param argsOrOptions Optional array of command-line arguments that have been
|
|
562
|
+
* parsed so far, or a {@link ParseOptions} object for annotations.
|
|
563
|
+
* When a `ParseOptions` is passed here, the `options` parameter is
|
|
564
|
+
* ignored. Defaults to an empty array when omitted.
|
|
565
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
566
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
555
567
|
* @returns For sync parsers, returns a {@link DocPage} directly.
|
|
556
568
|
* For async parsers, returns a Promise of {@link DocPage}.
|
|
557
569
|
* Returns `undefined` if no documentation can be generated.
|
|
@@ -571,9 +583,11 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
571
583
|
* ```
|
|
572
584
|
* @since 0.9.0 Updated to support async parsers.
|
|
573
585
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
586
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
587
|
+
* directly.
|
|
574
588
|
*/
|
|
575
|
-
declare function getDocPage(parser: Parser<"sync", unknown, unknown>,
|
|
576
|
-
declare function getDocPage(parser: Parser<"async", unknown, unknown>,
|
|
577
|
-
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>,
|
|
589
|
+
declare function getDocPage(parser: Parser<"sync", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): DocPage | undefined;
|
|
590
|
+
declare function getDocPage(parser: Parser<"async", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
|
|
591
|
+
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): ModeValue<M, DocPage | undefined>;
|
|
578
592
|
//#endregion
|
|
579
593
|
export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, GroupOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
|
package/dist/parser.d.ts
CHANGED
|
@@ -511,13 +511,18 @@ declare function suggest<M extends Mode, T>(parser: Parser<M, T, unknown>, args:
|
|
|
511
511
|
* in a Promise).
|
|
512
512
|
*
|
|
513
513
|
* @param parser The sync parser to generate documentation for.
|
|
514
|
-
* @param
|
|
515
|
-
*
|
|
514
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
515
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
516
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
517
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
518
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
516
519
|
* @returns A {@link DocPage} or `undefined`.
|
|
517
520
|
* @since 0.9.0
|
|
518
521
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
522
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
523
|
+
* directly.
|
|
519
524
|
*/
|
|
520
|
-
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>,
|
|
525
|
+
declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): DocPage | undefined;
|
|
521
526
|
/**
|
|
522
527
|
* Generates a documentation page for any parser, returning a Promise.
|
|
523
528
|
*
|
|
@@ -526,13 +531,18 @@ declare function getDocPageSync(parser: Parser<"sync", unknown, unknown>, args?:
|
|
|
526
531
|
* async value parsers.
|
|
527
532
|
*
|
|
528
533
|
* @param parser The parser to generate documentation for.
|
|
529
|
-
* @param
|
|
530
|
-
*
|
|
534
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
535
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
536
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
537
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
538
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
531
539
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
532
540
|
* @since 0.9.0
|
|
533
541
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
542
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
543
|
+
* directly.
|
|
534
544
|
*/
|
|
535
|
-
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>,
|
|
545
|
+
declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
|
|
536
546
|
/**
|
|
537
547
|
* Generates a documentation page for a parser based on its current state after
|
|
538
548
|
* attempting to parse the provided arguments. This function is useful for
|
|
@@ -548,10 +558,12 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
548
558
|
* For async parsers, returns a Promise of the documentation page.
|
|
549
559
|
*
|
|
550
560
|
* @param parser The parser to generate documentation for
|
|
551
|
-
* @param
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
561
|
+
* @param argsOrOptions Optional array of command-line arguments that have been
|
|
562
|
+
* parsed so far, or a {@link ParseOptions} object for annotations.
|
|
563
|
+
* When a `ParseOptions` is passed here, the `options` parameter is
|
|
564
|
+
* ignored. Defaults to an empty array when omitted.
|
|
565
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
566
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
555
567
|
* @returns For sync parsers, returns a {@link DocPage} directly.
|
|
556
568
|
* For async parsers, returns a Promise of {@link DocPage}.
|
|
557
569
|
* Returns `undefined` if no documentation can be generated.
|
|
@@ -571,9 +583,11 @@ declare function getDocPageAsync(parser: Parser<Mode, unknown, unknown>, args?:
|
|
|
571
583
|
* ```
|
|
572
584
|
* @since 0.9.0 Updated to support async parsers.
|
|
573
585
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
586
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
587
|
+
* directly.
|
|
574
588
|
*/
|
|
575
|
-
declare function getDocPage(parser: Parser<"sync", unknown, unknown>,
|
|
576
|
-
declare function getDocPage(parser: Parser<"async", unknown, unknown>,
|
|
577
|
-
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>,
|
|
589
|
+
declare function getDocPage(parser: Parser<"sync", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): DocPage | undefined;
|
|
590
|
+
declare function getDocPage(parser: Parser<"async", unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): Promise<DocPage | undefined>;
|
|
591
|
+
declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, argsOrOptions?: readonly string[] | ParseOptions, options?: ParseOptions): ModeValue<M, DocPage | undefined>;
|
|
578
592
|
//#endregion
|
|
579
593
|
export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, GroupOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
|
package/dist/parser.js
CHANGED
|
@@ -299,14 +299,20 @@ function findCommandInExclusive(term, commandName) {
|
|
|
299
299
|
* in a Promise).
|
|
300
300
|
*
|
|
301
301
|
* @param parser The sync parser to generate documentation for.
|
|
302
|
-
* @param
|
|
303
|
-
*
|
|
302
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
303
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
304
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
305
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
306
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
304
307
|
* @returns A {@link DocPage} or `undefined`.
|
|
305
308
|
* @since 0.9.0
|
|
306
309
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
310
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
311
|
+
* directly.
|
|
307
312
|
*/
|
|
308
|
-
function getDocPageSync(parser,
|
|
309
|
-
return getDocPageSyncImpl(parser,
|
|
313
|
+
function getDocPageSync(parser, argsOrOptions, options) {
|
|
314
|
+
if (Array.isArray(argsOrOptions)) return getDocPageSyncImpl(parser, argsOrOptions, options);
|
|
315
|
+
return getDocPageSyncImpl(parser, [], argsOrOptions ?? options);
|
|
310
316
|
}
|
|
311
317
|
/**
|
|
312
318
|
* Generates a documentation page for any parser, returning a Promise.
|
|
@@ -316,19 +322,28 @@ function getDocPageSync(parser, args = [], options) {
|
|
|
316
322
|
* async value parsers.
|
|
317
323
|
*
|
|
318
324
|
* @param parser The parser to generate documentation for.
|
|
319
|
-
* @param
|
|
320
|
-
*
|
|
325
|
+
* @param argsOrOptions Optional array of command-line arguments for context,
|
|
326
|
+
* or a {@link ParseOptions} object for annotations. When a
|
|
327
|
+
* `ParseOptions` is passed here, the `options` parameter is ignored.
|
|
328
|
+
* @param options Optional {@link ParseOptions} for customizing parsing
|
|
329
|
+
* behavior. Only used when `argsOrOptions` is an array or omitted.
|
|
321
330
|
* @returns A Promise of {@link DocPage} or `undefined`.
|
|
322
331
|
* @since 0.9.0
|
|
323
332
|
* @since 0.10.0 Added optional `options` parameter for annotations support.
|
|
333
|
+
* @since 1.0.0 The second parameter now also accepts a `ParseOptions` object
|
|
334
|
+
* directly.
|
|
324
335
|
*/
|
|
325
|
-
function getDocPageAsync(parser,
|
|
326
|
-
|
|
327
|
-
|
|
336
|
+
function getDocPageAsync(parser, argsOrOptions, options) {
|
|
337
|
+
const args = Array.isArray(argsOrOptions) ? argsOrOptions : [];
|
|
338
|
+
const opts = Array.isArray(argsOrOptions) ? options : argsOrOptions ?? options;
|
|
339
|
+
if (parser.$mode === "sync") return Promise.resolve(getDocPageSyncImpl(parser, args, opts));
|
|
340
|
+
return getDocPageAsyncImpl(parser, args, opts);
|
|
328
341
|
}
|
|
329
|
-
function getDocPage(parser,
|
|
330
|
-
|
|
331
|
-
|
|
342
|
+
function getDocPage(parser, argsOrOptions, options) {
|
|
343
|
+
const args = Array.isArray(argsOrOptions) ? argsOrOptions : [];
|
|
344
|
+
const opts = Array.isArray(argsOrOptions) ? options : argsOrOptions ?? options;
|
|
345
|
+
if (parser.$mode === "sync") return getDocPageSyncImpl(parser, args, opts);
|
|
346
|
+
return getDocPageAsyncImpl(parser, args, opts);
|
|
332
347
|
}
|
|
333
348
|
/**
|
|
334
349
|
* Internal sync implementation of getDocPage.
|
package/dist/usage.cjs
CHANGED
|
@@ -121,10 +121,8 @@ function extractCommandNames(usage, includeHidden) {
|
|
|
121
121
|
* appearing before commands due to priority sorting) and false negatives
|
|
122
122
|
* (e.g., options after commands that are actually parallel peers).
|
|
123
123
|
* The proper fix is to use `Parser.leadingNames` instead of usage-tree
|
|
124
|
-
* analysis.
|
|
125
|
-
*
|
|
126
|
-
* See https://github.com/dahlia/optique/issues/734 and
|
|
127
|
-
* https://github.com/dahlia/optique/issues/735
|
|
124
|
+
* analysis.
|
|
125
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
128
126
|
*
|
|
129
127
|
* @param usage The usage description to extract leading option names from.
|
|
130
128
|
* @param includeHidden Whether to include fully hidden options
|
|
@@ -172,10 +170,9 @@ function extractLeadingOptionNames(usage, includeHidden) {
|
|
|
172
170
|
* `exclusive` containers, since they represent alternatives or optional
|
|
173
171
|
* wrappers at the same token position.
|
|
174
172
|
*
|
|
175
|
-
* Known limitation: this function has the same usage-tree ordering
|
|
176
|
-
*
|
|
177
|
-
* See https://github.com/dahlia/optique/issues/
|
|
178
|
-
* https://github.com/dahlia/optique/issues/735
|
|
173
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
174
|
+
* as {@link extractLeadingOptionNames}.
|
|
175
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
179
176
|
*
|
|
180
177
|
* @param usage The usage description to extract leading command names from.
|
|
181
178
|
* @param includeHidden Whether to include fully hidden commands
|
|
@@ -212,27 +209,86 @@ function extractLeadingCommandNames(usage, includeHidden) {
|
|
|
212
209
|
return names;
|
|
213
210
|
}
|
|
214
211
|
/**
|
|
212
|
+
* Extracts literal values that could match as the first positional token.
|
|
213
|
+
*
|
|
214
|
+
* Unlike {@link extractLiteralValues}, which traverses the entire usage tree,
|
|
215
|
+
* this function stops scanning a terms array after encountering a `command`,
|
|
216
|
+
* `argument`, or `literal` term, because subsequent terms in that array are
|
|
217
|
+
* scoped under that positional token. It still recurses into `optional`,
|
|
218
|
+
* `multiple`, and `exclusive` containers.
|
|
219
|
+
*
|
|
220
|
+
* Literals tagged with `optionValue: true` (produced by
|
|
221
|
+
* `appendLiteralToUsage()` when rewriting option metavars for
|
|
222
|
+
* `conditional()` discriminators) are skipped, because they represent
|
|
223
|
+
* option values rather than standalone positional tokens.
|
|
224
|
+
*
|
|
225
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
226
|
+
* as {@link extractLeadingOptionNames}.
|
|
227
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
228
|
+
*
|
|
229
|
+
* @param usage The usage description to extract leading literal values from.
|
|
230
|
+
* @returns A set of literal values that could match at the first token
|
|
231
|
+
* position.
|
|
232
|
+
* @since 1.0.0
|
|
233
|
+
*/
|
|
234
|
+
function extractLeadingLiteralValues(usage) {
|
|
235
|
+
const values = /* @__PURE__ */ new Set();
|
|
236
|
+
function collectLeading(terms) {
|
|
237
|
+
if (!terms || !Array.isArray(terms)) return;
|
|
238
|
+
for (const term of terms) switch (term.type) {
|
|
239
|
+
case "literal":
|
|
240
|
+
if (term.optionValue) break;
|
|
241
|
+
values.add(term.value);
|
|
242
|
+
return;
|
|
243
|
+
case "command":
|
|
244
|
+
case "argument": return;
|
|
245
|
+
case "optional":
|
|
246
|
+
collectLeading(term.terms);
|
|
247
|
+
break;
|
|
248
|
+
case "multiple":
|
|
249
|
+
collectLeading(term.terms);
|
|
250
|
+
if (term.min > 0 && branchConsumesToken(term.terms, true)) return;
|
|
251
|
+
break;
|
|
252
|
+
case "exclusive":
|
|
253
|
+
for (const branch of term.terms) collectLeading(branch);
|
|
254
|
+
if (exclusiveConsumesToken(term.terms, true)) return;
|
|
255
|
+
break;
|
|
256
|
+
default: break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
collectLeading(usage);
|
|
260
|
+
return values;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
215
263
|
* Checks whether every branch of an exclusive term must consume a positional
|
|
216
264
|
* token. When true, terms after the exclusive are at position N+1 and should
|
|
217
265
|
* not be considered "leading".
|
|
266
|
+
*
|
|
267
|
+
* @param skipOptionValueLiterals When `true`, literals tagged with
|
|
268
|
+
* `optionValue` are treated as non-positional. Only
|
|
269
|
+
* `extractLeadingLiteralValues()` passes `true`; the option/command
|
|
270
|
+
* extractors use the default (`false`) so that option+value pairs
|
|
271
|
+
* still act as positional gates.
|
|
218
272
|
*/
|
|
219
|
-
function exclusiveConsumesToken(branches) {
|
|
273
|
+
function exclusiveConsumesToken(branches, skipOptionValueLiterals = false) {
|
|
220
274
|
if (branches.length === 0) return false;
|
|
221
|
-
return branches.every((branch) => branchConsumesToken(branch));
|
|
275
|
+
return branches.every((branch) => branchConsumesToken(branch, skipOptionValueLiterals));
|
|
222
276
|
}
|
|
223
|
-
function branchConsumesToken(terms) {
|
|
277
|
+
function branchConsumesToken(terms, skipOptionValueLiterals = false) {
|
|
224
278
|
if (!terms || !Array.isArray(terms)) return false;
|
|
225
279
|
for (const term of terms) switch (term.type) {
|
|
226
280
|
case "command":
|
|
227
|
-
case "argument":
|
|
228
|
-
case "literal":
|
|
281
|
+
case "argument": return true;
|
|
282
|
+
case "literal":
|
|
283
|
+
if (skipOptionValueLiterals && term.optionValue) break;
|
|
284
|
+
return true;
|
|
229
285
|
case "option": break;
|
|
230
286
|
case "optional": break;
|
|
231
287
|
case "multiple":
|
|
232
|
-
if (term.min > 0 && branchConsumesToken(term.terms)) return true;
|
|
288
|
+
if (term.min > 0 && branchConsumesToken(term.terms, skipOptionValueLiterals)) return true;
|
|
233
289
|
break;
|
|
234
290
|
case "exclusive":
|
|
235
|
-
if (exclusiveConsumesToken(term.terms)) return true;
|
|
291
|
+
if (exclusiveConsumesToken(term.terms, skipOptionValueLiterals)) return true;
|
|
236
292
|
break;
|
|
237
293
|
default: break;
|
|
238
294
|
}
|
|
@@ -714,6 +770,7 @@ exports.cloneUsageTerm = cloneUsageTerm;
|
|
|
714
770
|
exports.extractArgumentMetavars = extractArgumentMetavars;
|
|
715
771
|
exports.extractCommandNames = extractCommandNames;
|
|
716
772
|
exports.extractLeadingCommandNames = extractLeadingCommandNames;
|
|
773
|
+
exports.extractLeadingLiteralValues = extractLeadingLiteralValues;
|
|
717
774
|
exports.extractLeadingOptionNames = extractLeadingOptionNames;
|
|
718
775
|
exports.extractLiteralValues = extractLiteralValues;
|
|
719
776
|
exports.extractOptionNames = extractOptionNames;
|
package/dist/usage.d.cts
CHANGED
|
@@ -178,6 +178,18 @@ type UsageTerm =
|
|
|
178
178
|
* The literal value that must be provided exactly as written.
|
|
179
179
|
*/
|
|
180
180
|
readonly value: string;
|
|
181
|
+
/**
|
|
182
|
+
* When `true`, this literal was derived from an option's metavar by
|
|
183
|
+
* `appendLiteralToUsage()` in `conditional()` and represents an option
|
|
184
|
+
* value, not a standalone positional token.
|
|
185
|
+
* {@link extractLeadingLiteralValues} and the `skipOptionValueLiterals`
|
|
186
|
+
* mode of `branchConsumesToken()` use this to distinguish option values
|
|
187
|
+
* from real positional literals. {@link extractLeadingOptionNames} and
|
|
188
|
+
* {@link extractLeadingCommandNames} intentionally still treat these
|
|
189
|
+
* literals as positional gates.
|
|
190
|
+
* @since 1.0.0
|
|
191
|
+
*/
|
|
192
|
+
readonly optionValue?: boolean;
|
|
181
193
|
}
|
|
182
194
|
/**
|
|
183
195
|
* A pass-through term, which represents unrecognized options that are
|
|
@@ -276,10 +288,8 @@ declare function extractCommandNames(usage: Usage, includeHidden?: boolean): Set
|
|
|
276
288
|
* appearing before commands due to priority sorting) and false negatives
|
|
277
289
|
* (e.g., options after commands that are actually parallel peers).
|
|
278
290
|
* The proper fix is to use `Parser.leadingNames` instead of usage-tree
|
|
279
|
-
* analysis.
|
|
280
|
-
*
|
|
281
|
-
* See https://github.com/dahlia/optique/issues/734 and
|
|
282
|
-
* https://github.com/dahlia/optique/issues/735
|
|
291
|
+
* analysis.
|
|
292
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
283
293
|
*
|
|
284
294
|
* @param usage The usage description to extract leading option names from.
|
|
285
295
|
* @param includeHidden Whether to include fully hidden options
|
|
@@ -299,10 +309,9 @@ declare function extractLeadingOptionNames(usage: Usage, includeHidden?: boolean
|
|
|
299
309
|
* `exclusive` containers, since they represent alternatives or optional
|
|
300
310
|
* wrappers at the same token position.
|
|
301
311
|
*
|
|
302
|
-
* Known limitation: this function has the same usage-tree ordering
|
|
303
|
-
*
|
|
304
|
-
* See https://github.com/dahlia/optique/issues/
|
|
305
|
-
* https://github.com/dahlia/optique/issues/735
|
|
312
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
313
|
+
* as {@link extractLeadingOptionNames}.
|
|
314
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
306
315
|
*
|
|
307
316
|
* @param usage The usage description to extract leading command names from.
|
|
308
317
|
* @param includeHidden Whether to include fully hidden commands
|
|
@@ -311,6 +320,30 @@ declare function extractLeadingOptionNames(usage: Usage, includeHidden?: boolean
|
|
|
311
320
|
* @since 1.0.0
|
|
312
321
|
*/
|
|
313
322
|
declare function extractLeadingCommandNames(usage: Usage, includeHidden?: boolean): Set<string>;
|
|
323
|
+
/**
|
|
324
|
+
* Extracts literal values that could match as the first positional token.
|
|
325
|
+
*
|
|
326
|
+
* Unlike {@link extractLiteralValues}, which traverses the entire usage tree,
|
|
327
|
+
* this function stops scanning a terms array after encountering a `command`,
|
|
328
|
+
* `argument`, or `literal` term, because subsequent terms in that array are
|
|
329
|
+
* scoped under that positional token. It still recurses into `optional`,
|
|
330
|
+
* `multiple`, and `exclusive` containers.
|
|
331
|
+
*
|
|
332
|
+
* Literals tagged with `optionValue: true` (produced by
|
|
333
|
+
* `appendLiteralToUsage()` when rewriting option metavars for
|
|
334
|
+
* `conditional()` discriminators) are skipped, because they represent
|
|
335
|
+
* option values rather than standalone positional tokens.
|
|
336
|
+
*
|
|
337
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
338
|
+
* as {@link extractLeadingOptionNames}.
|
|
339
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
340
|
+
*
|
|
341
|
+
* @param usage The usage description to extract leading literal values from.
|
|
342
|
+
* @returns A set of literal values that could match at the first token
|
|
343
|
+
* position.
|
|
344
|
+
* @since 1.0.0
|
|
345
|
+
*/
|
|
346
|
+
declare function extractLeadingLiteralValues(usage: Usage): Set<string>;
|
|
314
347
|
/**
|
|
315
348
|
* Extracts all literal values from a usage description.
|
|
316
349
|
*
|
|
@@ -487,4 +520,4 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
|
|
|
487
520
|
*/
|
|
488
521
|
declare function formatUsageTerm(term: UsageTerm, options?: UsageTermFormatOptions): string;
|
|
489
522
|
//#endregion
|
|
490
|
-
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
|
523
|
+
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
package/dist/usage.d.ts
CHANGED
|
@@ -178,6 +178,18 @@ type UsageTerm =
|
|
|
178
178
|
* The literal value that must be provided exactly as written.
|
|
179
179
|
*/
|
|
180
180
|
readonly value: string;
|
|
181
|
+
/**
|
|
182
|
+
* When `true`, this literal was derived from an option's metavar by
|
|
183
|
+
* `appendLiteralToUsage()` in `conditional()` and represents an option
|
|
184
|
+
* value, not a standalone positional token.
|
|
185
|
+
* {@link extractLeadingLiteralValues} and the `skipOptionValueLiterals`
|
|
186
|
+
* mode of `branchConsumesToken()` use this to distinguish option values
|
|
187
|
+
* from real positional literals. {@link extractLeadingOptionNames} and
|
|
188
|
+
* {@link extractLeadingCommandNames} intentionally still treat these
|
|
189
|
+
* literals as positional gates.
|
|
190
|
+
* @since 1.0.0
|
|
191
|
+
*/
|
|
192
|
+
readonly optionValue?: boolean;
|
|
181
193
|
}
|
|
182
194
|
/**
|
|
183
195
|
* A pass-through term, which represents unrecognized options that are
|
|
@@ -276,10 +288,8 @@ declare function extractCommandNames(usage: Usage, includeHidden?: boolean): Set
|
|
|
276
288
|
* appearing before commands due to priority sorting) and false negatives
|
|
277
289
|
* (e.g., options after commands that are actually parallel peers).
|
|
278
290
|
* The proper fix is to use `Parser.leadingNames` instead of usage-tree
|
|
279
|
-
* analysis.
|
|
280
|
-
*
|
|
281
|
-
* See https://github.com/dahlia/optique/issues/734 and
|
|
282
|
-
* https://github.com/dahlia/optique/issues/735
|
|
291
|
+
* analysis.
|
|
292
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
283
293
|
*
|
|
284
294
|
* @param usage The usage description to extract leading option names from.
|
|
285
295
|
* @param includeHidden Whether to include fully hidden options
|
|
@@ -299,10 +309,9 @@ declare function extractLeadingOptionNames(usage: Usage, includeHidden?: boolean
|
|
|
299
309
|
* `exclusive` containers, since they represent alternatives or optional
|
|
300
310
|
* wrappers at the same token position.
|
|
301
311
|
*
|
|
302
|
-
* Known limitation: this function has the same usage-tree ordering
|
|
303
|
-
*
|
|
304
|
-
* See https://github.com/dahlia/optique/issues/
|
|
305
|
-
* https://github.com/dahlia/optique/issues/735
|
|
312
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
313
|
+
* as {@link extractLeadingOptionNames}.
|
|
314
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
306
315
|
*
|
|
307
316
|
* @param usage The usage description to extract leading command names from.
|
|
308
317
|
* @param includeHidden Whether to include fully hidden commands
|
|
@@ -311,6 +320,30 @@ declare function extractLeadingOptionNames(usage: Usage, includeHidden?: boolean
|
|
|
311
320
|
* @since 1.0.0
|
|
312
321
|
*/
|
|
313
322
|
declare function extractLeadingCommandNames(usage: Usage, includeHidden?: boolean): Set<string>;
|
|
323
|
+
/**
|
|
324
|
+
* Extracts literal values that could match as the first positional token.
|
|
325
|
+
*
|
|
326
|
+
* Unlike {@link extractLiteralValues}, which traverses the entire usage tree,
|
|
327
|
+
* this function stops scanning a terms array after encountering a `command`,
|
|
328
|
+
* `argument`, or `literal` term, because subsequent terms in that array are
|
|
329
|
+
* scoped under that positional token. It still recurses into `optional`,
|
|
330
|
+
* `multiple`, and `exclusive` containers.
|
|
331
|
+
*
|
|
332
|
+
* Literals tagged with `optionValue: true` (produced by
|
|
333
|
+
* `appendLiteralToUsage()` when rewriting option metavars for
|
|
334
|
+
* `conditional()` discriminators) are skipped, because they represent
|
|
335
|
+
* option values rather than standalone positional tokens.
|
|
336
|
+
*
|
|
337
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
338
|
+
* as {@link extractLeadingOptionNames}.
|
|
339
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
340
|
+
*
|
|
341
|
+
* @param usage The usage description to extract leading literal values from.
|
|
342
|
+
* @returns A set of literal values that could match at the first token
|
|
343
|
+
* position.
|
|
344
|
+
* @since 1.0.0
|
|
345
|
+
*/
|
|
346
|
+
declare function extractLeadingLiteralValues(usage: Usage): Set<string>;
|
|
314
347
|
/**
|
|
315
348
|
* Extracts all literal values from a usage description.
|
|
316
349
|
*
|
|
@@ -487,4 +520,4 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
|
|
|
487
520
|
*/
|
|
488
521
|
declare function formatUsageTerm(term: UsageTerm, options?: UsageTermFormatOptions): string;
|
|
489
522
|
//#endregion
|
|
490
|
-
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
|
523
|
+
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
package/dist/usage.js
CHANGED
|
@@ -121,10 +121,8 @@ function extractCommandNames(usage, includeHidden) {
|
|
|
121
121
|
* appearing before commands due to priority sorting) and false negatives
|
|
122
122
|
* (e.g., options after commands that are actually parallel peers).
|
|
123
123
|
* The proper fix is to use `Parser.leadingNames` instead of usage-tree
|
|
124
|
-
* analysis.
|
|
125
|
-
*
|
|
126
|
-
* See https://github.com/dahlia/optique/issues/734 and
|
|
127
|
-
* https://github.com/dahlia/optique/issues/735
|
|
124
|
+
* analysis.
|
|
125
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
128
126
|
*
|
|
129
127
|
* @param usage The usage description to extract leading option names from.
|
|
130
128
|
* @param includeHidden Whether to include fully hidden options
|
|
@@ -172,10 +170,9 @@ function extractLeadingOptionNames(usage, includeHidden) {
|
|
|
172
170
|
* `exclusive` containers, since they represent alternatives or optional
|
|
173
171
|
* wrappers at the same token position.
|
|
174
172
|
*
|
|
175
|
-
* Known limitation: this function has the same usage-tree ordering
|
|
176
|
-
*
|
|
177
|
-
* See https://github.com/dahlia/optique/issues/
|
|
178
|
-
* https://github.com/dahlia/optique/issues/735
|
|
173
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
174
|
+
* as {@link extractLeadingOptionNames}.
|
|
175
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
179
176
|
*
|
|
180
177
|
* @param usage The usage description to extract leading command names from.
|
|
181
178
|
* @param includeHidden Whether to include fully hidden commands
|
|
@@ -212,27 +209,86 @@ function extractLeadingCommandNames(usage, includeHidden) {
|
|
|
212
209
|
return names;
|
|
213
210
|
}
|
|
214
211
|
/**
|
|
212
|
+
* Extracts literal values that could match as the first positional token.
|
|
213
|
+
*
|
|
214
|
+
* Unlike {@link extractLiteralValues}, which traverses the entire usage tree,
|
|
215
|
+
* this function stops scanning a terms array after encountering a `command`,
|
|
216
|
+
* `argument`, or `literal` term, because subsequent terms in that array are
|
|
217
|
+
* scoped under that positional token. It still recurses into `optional`,
|
|
218
|
+
* `multiple`, and `exclusive` containers.
|
|
219
|
+
*
|
|
220
|
+
* Literals tagged with `optionValue: true` (produced by
|
|
221
|
+
* `appendLiteralToUsage()` when rewriting option metavars for
|
|
222
|
+
* `conditional()` discriminators) are skipped, because they represent
|
|
223
|
+
* option values rather than standalone positional tokens.
|
|
224
|
+
*
|
|
225
|
+
* Known limitation: this function has the same usage-tree ordering caveat
|
|
226
|
+
* as {@link extractLeadingOptionNames}.
|
|
227
|
+
* See https://github.com/dahlia/optique/issues/735
|
|
228
|
+
*
|
|
229
|
+
* @param usage The usage description to extract leading literal values from.
|
|
230
|
+
* @returns A set of literal values that could match at the first token
|
|
231
|
+
* position.
|
|
232
|
+
* @since 1.0.0
|
|
233
|
+
*/
|
|
234
|
+
function extractLeadingLiteralValues(usage) {
|
|
235
|
+
const values = /* @__PURE__ */ new Set();
|
|
236
|
+
function collectLeading(terms) {
|
|
237
|
+
if (!terms || !Array.isArray(terms)) return;
|
|
238
|
+
for (const term of terms) switch (term.type) {
|
|
239
|
+
case "literal":
|
|
240
|
+
if (term.optionValue) break;
|
|
241
|
+
values.add(term.value);
|
|
242
|
+
return;
|
|
243
|
+
case "command":
|
|
244
|
+
case "argument": return;
|
|
245
|
+
case "optional":
|
|
246
|
+
collectLeading(term.terms);
|
|
247
|
+
break;
|
|
248
|
+
case "multiple":
|
|
249
|
+
collectLeading(term.terms);
|
|
250
|
+
if (term.min > 0 && branchConsumesToken(term.terms, true)) return;
|
|
251
|
+
break;
|
|
252
|
+
case "exclusive":
|
|
253
|
+
for (const branch of term.terms) collectLeading(branch);
|
|
254
|
+
if (exclusiveConsumesToken(term.terms, true)) return;
|
|
255
|
+
break;
|
|
256
|
+
default: break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
collectLeading(usage);
|
|
260
|
+
return values;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
215
263
|
* Checks whether every branch of an exclusive term must consume a positional
|
|
216
264
|
* token. When true, terms after the exclusive are at position N+1 and should
|
|
217
265
|
* not be considered "leading".
|
|
266
|
+
*
|
|
267
|
+
* @param skipOptionValueLiterals When `true`, literals tagged with
|
|
268
|
+
* `optionValue` are treated as non-positional. Only
|
|
269
|
+
* `extractLeadingLiteralValues()` passes `true`; the option/command
|
|
270
|
+
* extractors use the default (`false`) so that option+value pairs
|
|
271
|
+
* still act as positional gates.
|
|
218
272
|
*/
|
|
219
|
-
function exclusiveConsumesToken(branches) {
|
|
273
|
+
function exclusiveConsumesToken(branches, skipOptionValueLiterals = false) {
|
|
220
274
|
if (branches.length === 0) return false;
|
|
221
|
-
return branches.every((branch) => branchConsumesToken(branch));
|
|
275
|
+
return branches.every((branch) => branchConsumesToken(branch, skipOptionValueLiterals));
|
|
222
276
|
}
|
|
223
|
-
function branchConsumesToken(terms) {
|
|
277
|
+
function branchConsumesToken(terms, skipOptionValueLiterals = false) {
|
|
224
278
|
if (!terms || !Array.isArray(terms)) return false;
|
|
225
279
|
for (const term of terms) switch (term.type) {
|
|
226
280
|
case "command":
|
|
227
|
-
case "argument":
|
|
228
|
-
case "literal":
|
|
281
|
+
case "argument": return true;
|
|
282
|
+
case "literal":
|
|
283
|
+
if (skipOptionValueLiterals && term.optionValue) break;
|
|
284
|
+
return true;
|
|
229
285
|
case "option": break;
|
|
230
286
|
case "optional": break;
|
|
231
287
|
case "multiple":
|
|
232
|
-
if (term.min > 0 && branchConsumesToken(term.terms)) return true;
|
|
288
|
+
if (term.min > 0 && branchConsumesToken(term.terms, skipOptionValueLiterals)) return true;
|
|
233
289
|
break;
|
|
234
290
|
case "exclusive":
|
|
235
|
-
if (exclusiveConsumesToken(term.terms)) return true;
|
|
291
|
+
if (exclusiveConsumesToken(term.terms, skipOptionValueLiterals)) return true;
|
|
236
292
|
break;
|
|
237
293
|
default: break;
|
|
238
294
|
}
|
|
@@ -709,4 +765,4 @@ function* formatUsageTermInternal(term, options) {
|
|
|
709
765
|
}
|
|
710
766
|
|
|
711
767
|
//#endregion
|
|
712
|
-
export { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
|
768
|
+
export { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLeadingCommandNames, extractLeadingLiteralValues, extractLeadingOptionNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
package/dist/validate.cjs
CHANGED
|
@@ -118,12 +118,13 @@ function validateMetaNameCollisions(userNames, metaEntries) {
|
|
|
118
118
|
for (const name of names) {
|
|
119
119
|
if (optionNames.has(name)) throw new TypeError(`User-defined option "${name}" conflicts with the built-in ${label}.`);
|
|
120
120
|
if (commandNames.has(name)) throw new TypeError(`User-defined command "${name}" conflicts with the built-in ${label}.`);
|
|
121
|
-
|
|
121
|
+
const literalNames = kind === "command" ? userNames.leadingLiterals : userNames.allLiterals;
|
|
122
|
+
if (literalNames.has(name)) throw new TypeError(`Literal value "${name}" conflicts with the built-in ${label}.`);
|
|
122
123
|
if (prefixMatch) {
|
|
123
124
|
const prefix = name + "=";
|
|
124
125
|
for (const userName of optionNames) if (userName.startsWith(prefix)) throw new TypeError(`User-defined option "${userName}" conflicts with the built-in ${label} (prefix "${prefix}").`);
|
|
125
126
|
for (const userName of commandNames) if (userName.startsWith(prefix)) throw new TypeError(`User-defined command "${userName}" conflicts with the built-in ${label} (prefix "${prefix}").`);
|
|
126
|
-
for (const literal of
|
|
127
|
+
for (const literal of literalNames) if (literal.startsWith(prefix)) throw new TypeError(`Literal value "${literal}" conflicts with the built-in ${label} (prefix "${prefix}").`);
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
}
|
package/dist/validate.js
CHANGED
|
@@ -117,12 +117,13 @@ function validateMetaNameCollisions(userNames, metaEntries) {
|
|
|
117
117
|
for (const name of names) {
|
|
118
118
|
if (optionNames.has(name)) throw new TypeError(`User-defined option "${name}" conflicts with the built-in ${label}.`);
|
|
119
119
|
if (commandNames.has(name)) throw new TypeError(`User-defined command "${name}" conflicts with the built-in ${label}.`);
|
|
120
|
-
|
|
120
|
+
const literalNames = kind === "command" ? userNames.leadingLiterals : userNames.allLiterals;
|
|
121
|
+
if (literalNames.has(name)) throw new TypeError(`Literal value "${name}" conflicts with the built-in ${label}.`);
|
|
121
122
|
if (prefixMatch) {
|
|
122
123
|
const prefix = name + "=";
|
|
123
124
|
for (const userName of optionNames) if (userName.startsWith(prefix)) throw new TypeError(`User-defined option "${userName}" conflicts with the built-in ${label} (prefix "${prefix}").`);
|
|
124
125
|
for (const userName of commandNames) if (userName.startsWith(prefix)) throw new TypeError(`User-defined command "${userName}" conflicts with the built-in ${label} (prefix "${prefix}").`);
|
|
125
|
-
for (const literal of
|
|
126
|
+
for (const literal of literalNames) if (literal.startsWith(prefix)) throw new TypeError(`Literal value "${literal}" conflicts with the built-in ${label} (prefix "${prefix}").`);
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
}
|