@optique/core 1.4.0-dev.2606 → 1.4.0-dev.2607
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 +129 -78
- package/dist/constructs.js +129 -78
- package/dist/facade.cjs +3 -69
- package/dist/facade.js +1 -67
- package/dist/modifiers.cjs +6 -5
- package/dist/modifiers.js +6 -5
- package/dist/primitives.cjs +57 -13
- package/dist/primitives.d.cts +3 -3
- package/dist/primitives.d.ts +3 -3
- package/dist/primitives.js +57 -13
- package/dist/short-option.cjs +197 -0
- package/dist/short-option.js +186 -0
- package/dist/usage-internals.cjs +73 -0
- package/dist/usage-internals.js +71 -1
- package/package.json +2 -2
- package/skills/optique/SKILL.md +7 -7
package/dist/constructs.js
CHANGED
|
@@ -8,12 +8,13 @@ import { createDependencySourceState, dependencyId, isDependencySourceState, isP
|
|
|
8
8
|
import { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, completeEffectfulSourcesAsync, createDependencyRuntimeContext, effectfulSchedulingNodesKey, exclusiveSourceScopeKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, forkRuntimeForCommittedSubtree, getDefaultDependencySnapshot, guaranteedStaticSourceIdsKey, hasInactiveCompletion, isMatchedState, recordSourceScope, releaseUncollectedSourceValues, replaceCachedBarrierFailure, resolveDerivedSourceValues, resolveDerivedSourceValuesAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync, serializeSchedulingPath, sourceCollectionExpansionKey, staticSourceScopeKey } from "./dependency-runtime.js";
|
|
9
9
|
import { defineInheritedAnnotationParser, defineParseLanes, getOwnParseLanes, getParserSuggestRuntimeNodes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
10
10
|
import { annotationViewTargets, getWrappedChildParseState, getWrappedChildState, reconcileObjectChildState, unwrapAnnotationView } from "./annotation-state.js";
|
|
11
|
+
import { collectLeadingCandidates } from "./usage-internals.js";
|
|
12
|
+
import { adoptOptionScope, combinedOptionScope, conditionalOptionScope, forkOptionScope, restoreOptionScope, scopeParser, selectableOptionScope, withOptionScope, withParserOptionScope } from "./short-option.js";
|
|
11
13
|
import { allowDuplicateLeadingCommandNamesKey } from "./internal/command-alias.js";
|
|
12
14
|
import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
|
|
13
15
|
import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
|
|
14
16
|
import { fluent } from "./modifiers.js";
|
|
15
17
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, deduplicateSuggestions, expandCommandAliasSuggestions, findSimilar } from "./suggestion.js";
|
|
16
|
-
import { collectLeadingCandidates } from "./usage-internals.js";
|
|
17
18
|
|
|
18
19
|
//#region src/constructs.ts
|
|
19
20
|
/**
|
|
@@ -48,7 +49,7 @@ function withoutRepublishInstruction(exec) {
|
|
|
48
49
|
}
|
|
49
50
|
function withChildContext$1(context, segment, state, parser, usage) {
|
|
50
51
|
const childState = parser == null ? state : getWrappedChildParseState(context.state, state, parser);
|
|
51
|
-
return withChildContext(context, segment, childState, usage);
|
|
52
|
+
return withChildContext(parser == null ? context : withParserOptionScope(context, parser), segment, childState, usage);
|
|
52
53
|
}
|
|
53
54
|
function isUnmatchedDependencyState(state, parser) {
|
|
54
55
|
if (state === void 0) return true;
|
|
@@ -1402,7 +1403,7 @@ function or(...args) {
|
|
|
1402
1403
|
let optionsTerminatorResult = null;
|
|
1403
1404
|
let provisionalAmbiguous = false;
|
|
1404
1405
|
for (const [parser, i] of orderedParsers) {
|
|
1405
|
-
const result = parser.parse(withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser));
|
|
1406
|
+
const result = parser.parse(withChildContext$1(forkOptionScope(context), i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser));
|
|
1406
1407
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
1407
1408
|
if (activeState?.[0] === i && activeState[1].success && activeState[1].consumed.length > 0 && result.next.buffer.length < 1) return preserveExclusiveStateAfterOptionsTerminator(context, result);
|
|
1408
1409
|
optionsTerminatorResult ??= result;
|
|
@@ -1437,7 +1438,7 @@ function or(...args) {
|
|
|
1437
1438
|
return {
|
|
1438
1439
|
success: true,
|
|
1439
1440
|
next: {
|
|
1440
|
-
...context,
|
|
1441
|
+
...adoptOptionScope(context, result.next),
|
|
1441
1442
|
buffer: result.next.buffer,
|
|
1442
1443
|
optionsTerminated: result.next.optionsTerminated,
|
|
1443
1444
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1473,7 +1474,7 @@ function or(...args) {
|
|
|
1473
1474
|
return {
|
|
1474
1475
|
success: true,
|
|
1475
1476
|
next: {
|
|
1476
|
-
...context,
|
|
1477
|
+
...adoptOptionScope(context, replayedResult.next),
|
|
1477
1478
|
buffer: replayedResult.next.buffer,
|
|
1478
1479
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1479
1480
|
state: createExclusiveState(context.state, i, parser, {
|
|
@@ -1492,7 +1493,7 @@ function or(...args) {
|
|
|
1492
1493
|
return {
|
|
1493
1494
|
success: true,
|
|
1494
1495
|
next: {
|
|
1495
|
-
...context,
|
|
1496
|
+
...adoptOptionScope(context, result.next),
|
|
1496
1497
|
buffer: result.next.buffer,
|
|
1497
1498
|
optionsTerminated: result.next.optionsTerminated,
|
|
1498
1499
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1518,7 +1519,7 @@ function or(...args) {
|
|
|
1518
1519
|
success: true,
|
|
1519
1520
|
...zeroConsumedBranch.result.provisional ? { provisional: true } : {},
|
|
1520
1521
|
next: {
|
|
1521
|
-
...context,
|
|
1522
|
+
...adoptOptionScope(context, zeroConsumedBranch.result.next),
|
|
1522
1523
|
state: createExclusiveState(context.state, zeroConsumedBranch.index, zeroConsumedBranch.parser, zeroConsumedBranch.result),
|
|
1523
1524
|
...mergedExec != null ? {
|
|
1524
1525
|
exec: mergedExec,
|
|
@@ -1536,7 +1537,7 @@ function or(...args) {
|
|
|
1536
1537
|
success: true,
|
|
1537
1538
|
provisional: true,
|
|
1538
1539
|
next: {
|
|
1539
|
-
...context,
|
|
1540
|
+
...adoptOptionScope(context, provisionalConsuming.result.next),
|
|
1540
1541
|
buffer: provisionalConsuming.result.next.buffer,
|
|
1541
1542
|
optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
|
|
1542
1543
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
|
|
@@ -1551,7 +1552,7 @@ function or(...args) {
|
|
|
1551
1552
|
if (activeState != null && activeState[1].success) {
|
|
1552
1553
|
const previouslyConsumed = activeState[1].consumed;
|
|
1553
1554
|
const checkResult = provisionalConsuming.parser.parse({
|
|
1554
|
-
...withChildContext$1(context, provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1555
|
+
...withChildContext$1(forkOptionScope(context), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1555
1556
|
buffer: previouslyConsumed
|
|
1556
1557
|
});
|
|
1557
1558
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1570,7 +1571,7 @@ function or(...args) {
|
|
|
1570
1571
|
success: true,
|
|
1571
1572
|
provisional: true,
|
|
1572
1573
|
next: {
|
|
1573
|
-
...context,
|
|
1574
|
+
...adoptOptionScope(context, replayedResult.next),
|
|
1574
1575
|
buffer: replayedResult.next.buffer,
|
|
1575
1576
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1576
1577
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
|
|
@@ -1605,7 +1606,7 @@ function or(...args) {
|
|
|
1605
1606
|
let optionsTerminatorResult = null;
|
|
1606
1607
|
let provisionalAmbiguous = false;
|
|
1607
1608
|
for (const [parser, i] of orderedParsers) {
|
|
1608
|
-
const resultOrPromise = parser.parse(withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser));
|
|
1609
|
+
const resultOrPromise = parser.parse(withChildContext$1(forkOptionScope(context), i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser));
|
|
1609
1610
|
const result = await resultOrPromise;
|
|
1610
1611
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
1611
1612
|
if (activeState?.[0] === i && activeState[1].success && activeState[1].consumed.length > 0 && result.next.buffer.length < 1) return preserveExclusiveStateAfterOptionsTerminator(context, result);
|
|
@@ -1641,7 +1642,7 @@ function or(...args) {
|
|
|
1641
1642
|
return {
|
|
1642
1643
|
success: true,
|
|
1643
1644
|
next: {
|
|
1644
|
-
...context,
|
|
1645
|
+
...adoptOptionScope(context, result.next),
|
|
1645
1646
|
buffer: result.next.buffer,
|
|
1646
1647
|
optionsTerminated: result.next.optionsTerminated,
|
|
1647
1648
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1679,7 +1680,7 @@ function or(...args) {
|
|
|
1679
1680
|
return {
|
|
1680
1681
|
success: true,
|
|
1681
1682
|
next: {
|
|
1682
|
-
...context,
|
|
1683
|
+
...adoptOptionScope(context, replayedResult.next),
|
|
1683
1684
|
buffer: replayedResult.next.buffer,
|
|
1684
1685
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1685
1686
|
state: createExclusiveState(context.state, i, parser, {
|
|
@@ -1698,7 +1699,7 @@ function or(...args) {
|
|
|
1698
1699
|
return {
|
|
1699
1700
|
success: true,
|
|
1700
1701
|
next: {
|
|
1701
|
-
...context,
|
|
1702
|
+
...adoptOptionScope(context, result.next),
|
|
1702
1703
|
buffer: result.next.buffer,
|
|
1703
1704
|
optionsTerminated: result.next.optionsTerminated,
|
|
1704
1705
|
state: createExclusiveState(context.state, i, parser, result),
|
|
@@ -1724,7 +1725,7 @@ function or(...args) {
|
|
|
1724
1725
|
success: true,
|
|
1725
1726
|
...zeroConsumedBranch.result.provisional ? { provisional: true } : {},
|
|
1726
1727
|
next: {
|
|
1727
|
-
...context,
|
|
1728
|
+
...adoptOptionScope(context, zeroConsumedBranch.result.next),
|
|
1728
1729
|
state: createExclusiveState(context.state, zeroConsumedBranch.index, zeroConsumedBranch.parser, zeroConsumedBranch.result),
|
|
1729
1730
|
...mergedExec != null ? {
|
|
1730
1731
|
exec: mergedExec,
|
|
@@ -1742,7 +1743,7 @@ function or(...args) {
|
|
|
1742
1743
|
success: true,
|
|
1743
1744
|
provisional: true,
|
|
1744
1745
|
next: {
|
|
1745
|
-
...context,
|
|
1746
|
+
...adoptOptionScope(context, provisionalConsuming.result.next),
|
|
1746
1747
|
buffer: provisionalConsuming.result.next.buffer,
|
|
1747
1748
|
optionsTerminated: provisionalConsuming.result.next.optionsTerminated,
|
|
1748
1749
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, provisionalConsuming.result),
|
|
@@ -1757,7 +1758,7 @@ function or(...args) {
|
|
|
1757
1758
|
if (activeState != null && activeState[1].success) {
|
|
1758
1759
|
const previouslyConsumed = activeState[1].consumed;
|
|
1759
1760
|
const checkResult = await provisionalConsuming.parser.parse({
|
|
1760
|
-
...withChildContext$1(context, provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1761
|
+
...withChildContext$1(forkOptionScope(context), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1761
1762
|
buffer: previouslyConsumed
|
|
1762
1763
|
});
|
|
1763
1764
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1776,7 +1777,7 @@ function or(...args) {
|
|
|
1776
1777
|
success: true,
|
|
1777
1778
|
provisional: true,
|
|
1778
1779
|
next: {
|
|
1779
|
-
...context,
|
|
1780
|
+
...adoptOptionScope(context, replayedResult.next),
|
|
1780
1781
|
buffer: replayedResult.next.buffer,
|
|
1781
1782
|
optionsTerminated: replayedResult.next.optionsTerminated,
|
|
1782
1783
|
state: createExclusiveState(context.state, provisionalConsuming.index, provisionalConsuming.parser, {
|
|
@@ -1863,7 +1864,7 @@ function or(...args) {
|
|
|
1863
1864
|
if (singleDependencyMetadata != null) singleResult.dependencyMetadata = singleDependencyMetadata;
|
|
1864
1865
|
defineExclusiveSchedulingNodes(singleResult, parsers);
|
|
1865
1866
|
defineInheritedAnnotationParser(singleResult);
|
|
1866
|
-
return fluent(singleResult);
|
|
1867
|
+
return fluent(scopeParser(singleResult, combinedOptionScope(parsers)));
|
|
1867
1868
|
}
|
|
1868
1869
|
/**
|
|
1869
1870
|
* @since 0.5.0
|
|
@@ -1912,7 +1913,7 @@ function createLongestMatch(...args) {
|
|
|
1912
1913
|
return {
|
|
1913
1914
|
success: true,
|
|
1914
1915
|
next: {
|
|
1915
|
-
...context,
|
|
1916
|
+
...adoptOptionScope(context, selectedResult.next),
|
|
1916
1917
|
buffer: selectedResult.next.buffer,
|
|
1917
1918
|
optionsTerminated: selectedResult.next.optionsTerminated,
|
|
1918
1919
|
state: createExclusiveState(context.state, match.index, parser, selectedResult),
|
|
@@ -1952,7 +1953,7 @@ function createLongestMatch(...args) {
|
|
|
1952
1953
|
const activeState = normalizeExclusiveState(context.state);
|
|
1953
1954
|
for (let i = 0; i < syncParsers.length; i++) {
|
|
1954
1955
|
const parser = syncParsers[i];
|
|
1955
|
-
const childContext = withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser);
|
|
1956
|
+
const childContext = withChildContext$1(forkOptionScope(context), i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser);
|
|
1956
1957
|
const result = parser.parse(childContext);
|
|
1957
1958
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
1958
1959
|
optionsTerminatorMatches.push({
|
|
@@ -1988,7 +1989,7 @@ function createLongestMatch(...args) {
|
|
|
1988
1989
|
const activeState = normalizeExclusiveState(context.state);
|
|
1989
1990
|
for (let i = 0; i < parsers.length; i++) {
|
|
1990
1991
|
const parser = parsers[i];
|
|
1991
|
-
const childContext = withChildContext$1(context, i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser);
|
|
1992
|
+
const childContext = withChildContext$1(forkOptionScope(context), i, activeState == null || activeState[0] !== i || !activeState[1].success ? parser.initialState : activeState[1].next.state, parser);
|
|
1992
1993
|
const resultOrPromise = parser.parse(childContext);
|
|
1993
1994
|
const result = await resultOrPromise;
|
|
1994
1995
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
@@ -2079,7 +2080,7 @@ function createLongestMatch(...args) {
|
|
|
2079
2080
|
if (multiDependencyMetadata != null) multiResult.dependencyMetadata = multiDependencyMetadata;
|
|
2080
2081
|
defineExclusiveSchedulingNodes(multiResult, parsers);
|
|
2081
2082
|
defineInheritedAnnotationParser(multiResult);
|
|
2082
|
-
return fluent(multiResult);
|
|
2083
|
+
return fluent(scopeParser(multiResult, combinedOptionScope(parsers)));
|
|
2083
2084
|
}
|
|
2084
2085
|
/**
|
|
2085
2086
|
* Creates the initial parse error shared by object-like combinators.
|
|
@@ -3093,15 +3094,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3093
3094
|
});
|
|
3094
3095
|
defineParseLanes(objectParser, objectParseLanes);
|
|
3095
3096
|
defineInheritedAnnotationParser(objectParser);
|
|
3096
|
-
return fluent(objectParser);
|
|
3097
|
+
return fluent(scopeParser(objectParser, combinedOptionScope(parserPairs.map(([, p]) => p))));
|
|
3097
3098
|
}
|
|
3098
3099
|
function isParserLike(value) {
|
|
3099
3100
|
return value != null && (typeof value === "object" || typeof value === "function") && "parse" in value && "$valueType" in value && "$stateType" in value;
|
|
3100
3101
|
}
|
|
3101
3102
|
function tokenMatchesLeadingName(token, candidates) {
|
|
3102
3103
|
if (token == null) return false;
|
|
3103
|
-
for (const name of candidates.optionNames) if (token === name) return true;
|
|
3104
|
-
for (const name of candidates.joinedOptionNames) if (name.startsWith("/") && token.startsWith(`${name}:`) || (name.startsWith("--") || name.startsWith("-") && name.length > 2) && token.startsWith(`${name}=`)) return true;
|
|
3104
|
+
for (const name of candidates.optionNames) if (token === name || name.startsWith("-") && !name.startsWith("--") && name.length > 2 && token.startsWith(`${name}=`)) return true;
|
|
3105
|
+
for (const name of candidates.joinedOptionNames) if (/^-[^-]$/.test(name) && token.startsWith(name) || name.startsWith("/") && token.startsWith(`${name}:`) || (name.startsWith("--") || name.startsWith("-") && name.length > 2) && token.startsWith(`${name}=`)) return true;
|
|
3105
3106
|
for (const name of candidates.commandNames) if (token === name) return true;
|
|
3106
3107
|
return false;
|
|
3107
3108
|
}
|
|
@@ -3327,6 +3328,7 @@ function advanceSeqSuggestContextSync(context, parsers, initialStates) {
|
|
|
3327
3328
|
while (currentContext.state.index < parsers.length) {
|
|
3328
3329
|
const index = currentContext.state.index;
|
|
3329
3330
|
const parser = parsers[index];
|
|
3331
|
+
currentContext = withParserOptionScope(currentContext, parser);
|
|
3330
3332
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
3331
3333
|
if (currentContext.buffer.length < 1) break;
|
|
3332
3334
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialStates[index], currentContext, index, parsers)) {
|
|
@@ -3353,6 +3355,7 @@ async function advanceSeqSuggestContextAsync(context, parsers, initialStates) {
|
|
|
3353
3355
|
while (currentContext.state.index < parsers.length) {
|
|
3354
3356
|
const index = currentContext.state.index;
|
|
3355
3357
|
const parser = parsers[index];
|
|
3358
|
+
currentContext = withParserOptionScope(currentContext, parser);
|
|
3356
3359
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
3357
3360
|
if (currentContext.buffer.length < 1) break;
|
|
3358
3361
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialStates[index], currentContext, index, parsers)) {
|
|
@@ -4109,7 +4112,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
4109
4112
|
enumerable: false
|
|
4110
4113
|
});
|
|
4111
4114
|
defineInheritedAnnotationParser(tupleParser);
|
|
4112
|
-
return fluent(tupleParser);
|
|
4115
|
+
return fluent(scopeParser(tupleParser, combinedOptionScope(parsers)));
|
|
4113
4116
|
}
|
|
4114
4117
|
function seq(...rawArgs) {
|
|
4115
4118
|
const label = typeof rawArgs[0] === "string" ? rawArgs[0] : void 0;
|
|
@@ -4127,12 +4130,31 @@ function seq(...rawArgs) {
|
|
|
4127
4130
|
...result,
|
|
4128
4131
|
consumed: consumed.length + result.consumed
|
|
4129
4132
|
});
|
|
4133
|
+
const reachableSeqScope = (context) => {
|
|
4134
|
+
let end = Math.min(context.state.index + 1, parsers.length);
|
|
4135
|
+
while (end < parsers.length) {
|
|
4136
|
+
const index = end - 1;
|
|
4137
|
+
const child = parsers[index];
|
|
4138
|
+
if (context.buffer.length > 0 && !tokenMatchesLeadingName(context.buffer[0], leadingCandidatesAfter(parsers, end))) break;
|
|
4139
|
+
if (!parserCanSkipAt(child, getSeqChildState(context.state, index, child), context.exec, index)) break;
|
|
4140
|
+
end++;
|
|
4141
|
+
}
|
|
4142
|
+
return combinedOptionScope(parsers.slice(0, end));
|
|
4143
|
+
};
|
|
4144
|
+
const seqScope = selectableOptionScope(reachableSeqScope({
|
|
4145
|
+
state: initialState,
|
|
4146
|
+
buffer: [],
|
|
4147
|
+
usage: [],
|
|
4148
|
+
optionsTerminated: false
|
|
4149
|
+
}));
|
|
4130
4150
|
const parseSync = (context) => {
|
|
4131
4151
|
let currentContext = context;
|
|
4132
4152
|
const allConsumed = [];
|
|
4133
4153
|
while (currentContext.state.index < syncParsers.length) {
|
|
4134
4154
|
const index = currentContext.state.index;
|
|
4135
4155
|
const parser = syncParsers[index];
|
|
4156
|
+
seqScope.select(currentContext, reachableSeqScope(currentContext));
|
|
4157
|
+
currentContext = withParserOptionScope(currentContext, parser);
|
|
4136
4158
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
4137
4159
|
if (currentContext.buffer.length < 1) break;
|
|
4138
4160
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialState.states[index], currentContext, index, syncParsers)) {
|
|
@@ -4175,6 +4197,8 @@ function seq(...rawArgs) {
|
|
|
4175
4197
|
while (currentContext.state.index < parsers.length) {
|
|
4176
4198
|
const index = currentContext.state.index;
|
|
4177
4199
|
const parser = parsers[index];
|
|
4200
|
+
seqScope.select(currentContext, reachableSeqScope(currentContext));
|
|
4201
|
+
currentContext = withParserOptionScope(currentContext, parser);
|
|
4178
4202
|
const parserState = getSeqChildState(currentContext.state, index, parser);
|
|
4179
4203
|
if (currentContext.buffer.length < 1) break;
|
|
4180
4204
|
if (shouldAdvanceSeqBeforeParse(parser, parserState, initialState.states[index], currentContext, index, parsers)) {
|
|
@@ -4443,7 +4467,9 @@ function seq(...rawArgs) {
|
|
|
4443
4467
|
enumerable: false
|
|
4444
4468
|
});
|
|
4445
4469
|
defineInheritedAnnotationParser(seqParser);
|
|
4446
|
-
return fluent(seqParser)
|
|
4470
|
+
return fluent(scopeParser(seqParser, seqScope.source, (context) => {
|
|
4471
|
+
seqScope.select(context, reachableSeqScope(context));
|
|
4472
|
+
}));
|
|
4447
4473
|
}
|
|
4448
4474
|
function merge(...args) {
|
|
4449
4475
|
const label = typeof args[0] === "string" ? args[0] : void 0;
|
|
@@ -5437,7 +5463,7 @@ function merge(...args) {
|
|
|
5437
5463
|
};
|
|
5438
5464
|
defineParseLanes(mergeParser, mergeParseLanes);
|
|
5439
5465
|
defineInheritedAnnotationParser(mergeParser);
|
|
5440
|
-
return fluent(mergeParser);
|
|
5466
|
+
return fluent(scopeParser(mergeParser, combinedOptionScope(parsers)));
|
|
5441
5467
|
}
|
|
5442
5468
|
/**
|
|
5443
5469
|
* Builds a dependency registry from the pre-parsed context state and returns
|
|
@@ -6064,7 +6090,7 @@ function concat(...parsers) {
|
|
|
6064
6090
|
}
|
|
6065
6091
|
};
|
|
6066
6092
|
defineInheritedAnnotationParser(concatParser);
|
|
6067
|
-
return fluent(concatParser);
|
|
6093
|
+
return fluent(scopeParser(concatParser, combinedOptionScope(parsers)));
|
|
6068
6094
|
}
|
|
6069
6095
|
function group(label, parser, options = {}) {
|
|
6070
6096
|
validateLabel(label);
|
|
@@ -6174,7 +6200,7 @@ function group(label, parser, options = {}) {
|
|
|
6174
6200
|
configurable: true,
|
|
6175
6201
|
enumerable: false
|
|
6176
6202
|
});
|
|
6177
|
-
return fluent(groupParser);
|
|
6203
|
+
return fluent(scopeParser(groupParser, combinedOptionScope([parser])));
|
|
6178
6204
|
}
|
|
6179
6205
|
/**
|
|
6180
6206
|
* Creates a conditional parser that selects different branch parsers based on
|
|
@@ -6283,6 +6309,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6283
6309
|
const noMatchContext = analyzeNoMatchContext([discriminator, ...allBranchParsers]);
|
|
6284
6310
|
return options?.errors?.noMatch ? typeof options.errors.noMatch === "function" ? options.errors.noMatch(noMatchContext) : options.errors.noMatch : generateNoMatchError(noMatchContext);
|
|
6285
6311
|
};
|
|
6312
|
+
const optionScope = conditionalOptionScope(discriminator, defaultBranch, branchParsers.map(([, p]) => p));
|
|
6286
6313
|
const parseSync = (context) => {
|
|
6287
6314
|
const state = context.state ?? initialState;
|
|
6288
6315
|
const syncDiscriminator = discriminator;
|
|
@@ -6319,10 +6346,12 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6319
6346
|
const value = completionResult.value;
|
|
6320
6347
|
const branchParser = syncBranches[value];
|
|
6321
6348
|
if (branchParser) {
|
|
6349
|
+
const branchContext = forkOptionScope(context);
|
|
6350
|
+
optionScope.select(branchContext, branchParser);
|
|
6322
6351
|
const discriminatorExec = mergeChildExec(context.exec, discriminatorResult.next.exec);
|
|
6323
6352
|
const branchParseResult = branchParser.parse({
|
|
6324
6353
|
...withChildContext$1({
|
|
6325
|
-
...
|
|
6354
|
+
...branchContext,
|
|
6326
6355
|
...discriminatorExec != null ? {
|
|
6327
6356
|
exec: discriminatorExec,
|
|
6328
6357
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
@@ -6332,6 +6361,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6332
6361
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
6333
6362
|
});
|
|
6334
6363
|
if (branchParseResult.success) {
|
|
6364
|
+
if (discriminatorResult.consumed.length > 0 || branchParseResult.consumed.length > 0) adoptOptionScope(context, branchParseResult.next);
|
|
6335
6365
|
const mergedExec = mergeChildExec(discriminatorExec, branchParseResult.next.exec);
|
|
6336
6366
|
const isProvisional = branchParseResult.provisional || discriminatorResult.consumed.length === 0 && branchParseResult.consumed.length === 0 && (branchParser.leadingNames.size > 0 || branchParser.acceptingAnyToken);
|
|
6337
6367
|
return {
|
|
@@ -6356,26 +6386,29 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6356
6386
|
consumed: [...discriminatorResult.consumed, ...branchParseResult.consumed]
|
|
6357
6387
|
};
|
|
6358
6388
|
}
|
|
6359
|
-
if (discriminatorResult.consumed.length > 0)
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6389
|
+
if (discriminatorResult.consumed.length > 0) {
|
|
6390
|
+
optionScope.select(context, branchParser);
|
|
6391
|
+
return {
|
|
6392
|
+
success: true,
|
|
6393
|
+
next: {
|
|
6394
|
+
...discriminatorResult.next,
|
|
6395
|
+
state: {
|
|
6396
|
+
discriminatorState: annotatedDiscriminatorState,
|
|
6397
|
+
discriminatorValue: value,
|
|
6398
|
+
selectedBranch: {
|
|
6399
|
+
kind: "branch",
|
|
6400
|
+
key: value
|
|
6401
|
+
},
|
|
6402
|
+
branchState: getWrappedChildState(state, branchParser.initialState, branchParser)
|
|
6369
6403
|
},
|
|
6370
|
-
|
|
6404
|
+
...discriminatorExec != null ? {
|
|
6405
|
+
exec: discriminatorExec,
|
|
6406
|
+
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
6407
|
+
} : {}
|
|
6371
6408
|
},
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
} : {}
|
|
6376
|
-
},
|
|
6377
|
-
consumed: discriminatorResult.consumed
|
|
6378
|
-
};
|
|
6409
|
+
consumed: discriminatorResult.consumed
|
|
6410
|
+
};
|
|
6411
|
+
}
|
|
6379
6412
|
return branchParseResult;
|
|
6380
6413
|
}
|
|
6381
6414
|
}
|
|
@@ -6448,7 +6481,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6448
6481
|
if (discriminatorResult.consumed.length === 0 && discriminator.mode === "async") {
|
|
6449
6482
|
const discriminatorExec = mergeChildExec(context.exec, discriminatorResult.next.exec);
|
|
6450
6483
|
const speculationContext = {
|
|
6451
|
-
...context,
|
|
6484
|
+
...withOptionScope(context, unionLeadingNames([...branchParsers.map(([, p]) => p), ...defaultBranch ? [defaultBranch] : []])),
|
|
6452
6485
|
buffer: discriminatorResult.next.buffer,
|
|
6453
6486
|
optionsTerminated: discriminatorResult.next.optionsTerminated,
|
|
6454
6487
|
...discriminatorExec != null ? {
|
|
@@ -6462,7 +6495,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6462
6495
|
let speculativeError;
|
|
6463
6496
|
let ambiguous = false;
|
|
6464
6497
|
for (const [key, bp] of branchParsers) {
|
|
6465
|
-
const branchResult = await bp.parse(withChildContext$1(speculationContext, "_branch", bp.initialState, bp, bp.usage));
|
|
6498
|
+
const branchResult = await bp.parse(withChildContext$1(forkOptionScope(speculationContext), "_branch", bp.initialState, bp, bp.usage));
|
|
6466
6499
|
if (branchResult.success && branchResult.consumed.length > 0) {
|
|
6467
6500
|
if (branchResult.provisional) {
|
|
6468
6501
|
if (provisionalHit == null && !provisionalAmbiguous) provisionalHit = {
|
|
@@ -6495,11 +6528,12 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6495
6528
|
if (branchResult.success) {
|
|
6496
6529
|
const annotatedDiscriminatorState$2 = getWrappedChildState(state, discriminatorResult.next.state, discriminator);
|
|
6497
6530
|
const mergedExec = mergeChildExec(discriminatorExec, branchResult.next.exec);
|
|
6531
|
+
optionScope.select(context, bp);
|
|
6498
6532
|
return {
|
|
6499
6533
|
success: true,
|
|
6500
6534
|
provisional: true,
|
|
6501
6535
|
next: {
|
|
6502
|
-
...branchResult.next,
|
|
6536
|
+
...restoreOptionScope(branchResult.next, context),
|
|
6503
6537
|
state: {
|
|
6504
6538
|
...state,
|
|
6505
6539
|
discriminatorState: annotatedDiscriminatorState$2,
|
|
@@ -6521,14 +6555,15 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6521
6555
|
}
|
|
6522
6556
|
let deferredBranchState = state.branchState;
|
|
6523
6557
|
if (defaultBranch !== void 0 && !ambiguous && !provisionalAmbiguous) {
|
|
6524
|
-
const defaultResult = await defaultBranch.parse(withChildContext$1(speculationContext, "_branch", state.branchState ?? defaultBranch.initialState, defaultBranch, defaultBranch.usage));
|
|
6558
|
+
const defaultResult = await defaultBranch.parse(withChildContext$1(forkOptionScope(speculationContext), "_branch", state.branchState ?? defaultBranch.initialState, defaultBranch, defaultBranch.usage));
|
|
6525
6559
|
if (defaultResult.success && defaultResult.consumed.length > 0) {
|
|
6526
6560
|
const defaultExec = mergeChildExec(discriminatorExec ?? context.exec, defaultResult.next.exec);
|
|
6561
|
+
optionScope.select(context, defaultBranch);
|
|
6527
6562
|
return {
|
|
6528
6563
|
success: true,
|
|
6529
6564
|
...defaultResult.provisional ? { provisional: true } : {},
|
|
6530
6565
|
next: {
|
|
6531
|
-
...defaultResult.next,
|
|
6566
|
+
...restoreOptionScope(defaultResult.next, context),
|
|
6532
6567
|
state: {
|
|
6533
6568
|
...state,
|
|
6534
6569
|
selectedBranch: { kind: "default" },
|
|
@@ -6551,7 +6586,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6551
6586
|
success: true,
|
|
6552
6587
|
provisional: true,
|
|
6553
6588
|
next: {
|
|
6554
|
-
...speculationContext,
|
|
6589
|
+
...restoreOptionScope(speculationContext, context),
|
|
6555
6590
|
state: {
|
|
6556
6591
|
...state,
|
|
6557
6592
|
discriminatorState: annotatedDiscriminatorState$1,
|
|
@@ -6567,10 +6602,12 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6567
6602
|
const value = completionResult.value;
|
|
6568
6603
|
const branchParser = branches[value];
|
|
6569
6604
|
if (branchParser) {
|
|
6605
|
+
const branchContext = forkOptionScope(context);
|
|
6606
|
+
optionScope.select(branchContext, branchParser);
|
|
6570
6607
|
const discriminatorExec = mergeChildExec(context.exec, discriminatorResult.next.exec);
|
|
6571
6608
|
const branchParseResult = await branchParser.parse({
|
|
6572
6609
|
...withChildContext$1({
|
|
6573
|
-
...
|
|
6610
|
+
...branchContext,
|
|
6574
6611
|
...discriminatorExec != null ? {
|
|
6575
6612
|
exec: discriminatorExec,
|
|
6576
6613
|
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
@@ -6580,6 +6617,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6580
6617
|
optionsTerminated: discriminatorResult.next.optionsTerminated
|
|
6581
6618
|
});
|
|
6582
6619
|
if (branchParseResult.success) {
|
|
6620
|
+
if (discriminatorResult.consumed.length > 0 || branchParseResult.consumed.length > 0) adoptOptionScope(context, branchParseResult.next);
|
|
6583
6621
|
const mergedExec = mergeChildExec(discriminatorExec, branchParseResult.next.exec);
|
|
6584
6622
|
return {
|
|
6585
6623
|
success: true,
|
|
@@ -6603,26 +6641,29 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
6603
6641
|
consumed: [...discriminatorResult.consumed, ...branchParseResult.consumed]
|
|
6604
6642
|
};
|
|
6605
6643
|
}
|
|
6606
|
-
if (discriminatorResult.consumed.length > 0)
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6644
|
+
if (discriminatorResult.consumed.length > 0) {
|
|
6645
|
+
optionScope.select(context, branchParser);
|
|
6646
|
+
return {
|
|
6647
|
+
success: true,
|
|
6648
|
+
next: {
|
|
6649
|
+
...discriminatorResult.next,
|
|
6650
|
+
state: {
|
|
6651
|
+
discriminatorState: annotatedDiscriminatorState,
|
|
6652
|
+
discriminatorValue: value,
|
|
6653
|
+
selectedBranch: {
|
|
6654
|
+
kind: "branch",
|
|
6655
|
+
key: value
|
|
6656
|
+
},
|
|
6657
|
+
branchState: getWrappedChildState(state, branchParser.initialState, branchParser)
|
|
6616
6658
|
},
|
|
6617
|
-
|
|
6659
|
+
...discriminatorExec != null ? {
|
|
6660
|
+
exec: discriminatorExec,
|
|
6661
|
+
dependencyRegistry: discriminatorExec.dependencyRegistry
|
|
6662
|
+
} : {}
|
|
6618
6663
|
},
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
} : {}
|
|
6623
|
-
},
|
|
6624
|
-
consumed: discriminatorResult.consumed
|
|
6625
|
-
};
|
|
6664
|
+
consumed: discriminatorResult.consumed
|
|
6665
|
+
};
|
|
6666
|
+
}
|
|
6626
6667
|
return branchParseResult;
|
|
6627
6668
|
}
|
|
6628
6669
|
}
|
|
@@ -7296,7 +7337,9 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7296
7337
|
} : void 0, "_discriminator"));
|
|
7297
7338
|
if (discComplete.success && syncBranches[discComplete.value] !== void 0) {
|
|
7298
7339
|
const resolvedBranch = syncBranches[discComplete.value];
|
|
7299
|
-
|
|
7340
|
+
const branchContext = forkOptionScope(suggestContext);
|
|
7341
|
+
optionScope.select(branchContext, resolvedBranch);
|
|
7342
|
+
yield* resolvedBranch.suggest(withChildContext$1(branchContext, "_branch", state.branchState ?? resolvedBranch.initialState, resolvedBranch), prefix);
|
|
7300
7343
|
} else if (syncDefaultBranch !== void 0) yield* syncDefaultBranch.suggest(withChildContext$1(suggestContext, "_branch", state.branchState ?? syncDefaultBranch.initialState, syncDefaultBranch), prefix);
|
|
7301
7344
|
} else {
|
|
7302
7345
|
const branchParser = state.selectedBranch.kind === "default" ? syncDefaultBranch : syncBranches[state.selectedBranch.key];
|
|
@@ -7350,7 +7393,9 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7350
7393
|
} : void 0, "_discriminator"));
|
|
7351
7394
|
if (discComplete.success && branches[discComplete.value] !== void 0) {
|
|
7352
7395
|
const resolvedBranch = branches[discComplete.value];
|
|
7353
|
-
|
|
7396
|
+
const branchContext = forkOptionScope(suggestContext);
|
|
7397
|
+
optionScope.select(branchContext, resolvedBranch);
|
|
7398
|
+
yield* resolvedBranch.suggest(withChildContext$1(branchContext, "_branch", state.branchState ?? resolvedBranch.initialState, resolvedBranch), prefix);
|
|
7354
7399
|
discResolved = true;
|
|
7355
7400
|
}
|
|
7356
7401
|
}
|
|
@@ -7501,7 +7546,13 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7501
7546
|
configurable: true,
|
|
7502
7547
|
enumerable: false
|
|
7503
7548
|
});
|
|
7504
|
-
return fluent(conditionalParser)
|
|
7549
|
+
return fluent(scopeParser(conditionalParser, optionScope.source, (context) => {
|
|
7550
|
+
const selected = context.state?.selectedBranch;
|
|
7551
|
+
if (selected != null) {
|
|
7552
|
+
const branch = selected.kind === "default" ? defaultBranch : branches[selected.key];
|
|
7553
|
+
if (branch != null) optionScope.select(context, branch);
|
|
7554
|
+
}
|
|
7555
|
+
}));
|
|
7505
7556
|
}
|
|
7506
7557
|
|
|
7507
7558
|
//#endregion
|
package/dist/facade.cjs
CHANGED
|
@@ -12,6 +12,7 @@ const require_dependency_runtime = require('./dependency-runtime.cjs');
|
|
|
12
12
|
const require_input_trace = require('./input-trace.cjs');
|
|
13
13
|
const require_internal_parser = require('./internal/parser.cjs');
|
|
14
14
|
const require_completion = require('./completion.cjs');
|
|
15
|
+
const require_usage_internals = require('./usage-internals.cjs');
|
|
15
16
|
const require_command_alias = require('./internal/command-alias.cjs');
|
|
16
17
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
17
18
|
const require_modifiers = require('./modifiers.cjs');
|
|
@@ -749,83 +750,16 @@ function collectActiveValueOptionNames(usage, commandPath, includeDirectAfterCom
|
|
|
749
750
|
flag: /* @__PURE__ */ new Set()
|
|
750
751
|
};
|
|
751
752
|
if (commandPath.length === 0) {
|
|
752
|
-
collectRootOptionNames(usage, optionNames, rootLeadingNames);
|
|
753
|
+
require_usage_internals.collectRootOptionNames(usage, optionNames, rootLeadingNames);
|
|
753
754
|
return optionNames.value;
|
|
754
|
-
} else collectActiveOptionNames(usage, commandPath, optionNames, false, includeDirectAfterCommandOptions);
|
|
755
|
+
} else require_usage_internals.collectActiveOptionNames(usage, commandPath, optionNames, false, includeDirectAfterCommandOptions);
|
|
755
756
|
const names = new Set(optionNames.value);
|
|
756
757
|
for (const name of optionNames.flag) names.delete(name);
|
|
757
758
|
return names;
|
|
758
759
|
}
|
|
759
|
-
function collectRootOptionNames(usage, names, rootLeadingNames) {
|
|
760
|
-
for (const term of usage) collectRootOptionNamesFromTerm(term, names, rootLeadingNames);
|
|
761
|
-
}
|
|
762
|
-
function collectRootOptionNamesFromTerm(term, names, rootLeadingNames) {
|
|
763
|
-
switch (term.type) {
|
|
764
|
-
case "option":
|
|
765
|
-
for (const name of term.names) {
|
|
766
|
-
if (!rootLeadingNames.has(name)) continue;
|
|
767
|
-
if (term.metavar != null) names.value.add(name);
|
|
768
|
-
else names.flag.add(name);
|
|
769
|
-
}
|
|
770
|
-
return;
|
|
771
|
-
case "optional":
|
|
772
|
-
case "multiple":
|
|
773
|
-
case "sequence":
|
|
774
|
-
collectRootOptionNames(term.terms, names, rootLeadingNames);
|
|
775
|
-
return;
|
|
776
|
-
case "exclusive":
|
|
777
|
-
for (const branch of term.terms) collectRootOptionNames(branch, names, rootLeadingNames);
|
|
778
|
-
return;
|
|
779
|
-
case "argument":
|
|
780
|
-
case "command":
|
|
781
|
-
case "literal":
|
|
782
|
-
case "passthrough":
|
|
783
|
-
case "ellipsis": return;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
function collectActiveOptionNames(usage, commandPath, names, fromExclusive, includeDirectAfterCommandOptions) {
|
|
787
|
-
if (commandPath.length === 0) {
|
|
788
|
-
collectOptionNamesAtCurrentCommandDepth(usage, names, false);
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
const [commandName, ...rest] = commandPath;
|
|
792
|
-
for (let i = 0; i < usage.length; i++) {
|
|
793
|
-
const term = usage[i];
|
|
794
|
-
if (term.type === "command" && term.name === commandName) {
|
|
795
|
-
const remainingUsage = usage.slice(i + 1);
|
|
796
|
-
if (rest.length === 0) collectOptionNamesAtCurrentCommandDepth(remainingUsage, names, !fromExclusive && includeDirectAfterCommandOptions);
|
|
797
|
-
else collectActiveOptionNames(remainingUsage, rest, names, fromExclusive, includeDirectAfterCommandOptions);
|
|
798
|
-
} else if (term.type === "exclusive") for (const branch of term.terms) collectActiveOptionNames(branch, commandPath, names, true, includeDirectAfterCommandOptions);
|
|
799
|
-
else if (term.type === "optional" || term.type === "multiple" || term.type === "sequence") collectActiveOptionNames(term.terms, commandPath, names, fromExclusive, includeDirectAfterCommandOptions);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
760
|
function isRootOptionToken(token, rootOptionSuggestions) {
|
|
803
761
|
return token != null && rootOptionSuggestions.some((suggestion) => token === suggestion.text || token.startsWith(`${suggestion.text}=`));
|
|
804
762
|
}
|
|
805
|
-
function collectOptionNamesAtCurrentCommandDepth(usage, names, afterMatchedCommand) {
|
|
806
|
-
for (const term of usage) if (collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand)) return;
|
|
807
|
-
}
|
|
808
|
-
function collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand) {
|
|
809
|
-
switch (term.type) {
|
|
810
|
-
case "command": return !afterMatchedCommand;
|
|
811
|
-
case "option":
|
|
812
|
-
if (term.metavar != null) for (const name of term.names) names.value.add(name);
|
|
813
|
-
else for (const name of term.names) names.flag.add(name);
|
|
814
|
-
return false;
|
|
815
|
-
case "optional":
|
|
816
|
-
case "multiple":
|
|
817
|
-
case "sequence":
|
|
818
|
-
collectOptionNamesAtCurrentCommandDepth(term.terms, names, afterMatchedCommand);
|
|
819
|
-
return false;
|
|
820
|
-
case "exclusive":
|
|
821
|
-
for (const branch of term.terms) collectOptionNamesAtCurrentCommandDepth(branch, names, false);
|
|
822
|
-
return false;
|
|
823
|
-
case "argument":
|
|
824
|
-
case "literal":
|
|
825
|
-
case "passthrough":
|
|
826
|
-
case "ellipsis": return false;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
763
|
function getRootMetaOptionSuggestions(helpOptionConfig, helpOptionNames, versionOptionConfig, versionOptionNames) {
|
|
830
764
|
const suggestions = [];
|
|
831
765
|
if (helpOptionConfig != null && !require_usage.isSuggestionHidden(helpOptionConfig.hidden)) suggestions.push(...helpOptionNames.map((name) => ({
|