@optique/core 1.0.15 → 1.0.16-dev.2975
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/completion.cjs +1 -1
- package/dist/completion.js +1 -1
- package/dist/constructs.cjs +52 -18
- package/dist/constructs.js +53 -19
- package/dist/internal/command-doc-metadata.cjs +32 -4
- package/dist/internal/command-doc-metadata.js +30 -4
- package/dist/internal/command-usage.cjs +52 -0
- package/dist/internal/command-usage.js +47 -0
- package/dist/internal/parser.cjs +111 -7
- package/dist/internal/parser.js +111 -7
- package/dist/message.cjs +4 -3
- package/dist/message.js +4 -3
- package/dist/modifiers.cjs +15 -1
- package/dist/modifiers.js +16 -2
- package/dist/primitives.cjs +7 -4
- package/dist/primitives.js +8 -5
- package/dist/usage.cjs +7 -6
- package/dist/usage.js +7 -6
- package/package.json +1 -1
package/dist/completion.cjs
CHANGED
|
@@ -1451,7 +1451,7 @@ const fish = {
|
|
|
1451
1451
|
name: "fish",
|
|
1452
1452
|
generateScript(programName, args = []) {
|
|
1453
1453
|
validateProgramName(programName);
|
|
1454
|
-
const escapedArgs = args.map((arg) => `'${arg.replace(/'/g, "\\'")}'`).join(" ");
|
|
1454
|
+
const escapedArgs = args.map((arg) => `'${arg.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`).join(" ");
|
|
1455
1455
|
const functionName = `__${programName}_complete`;
|
|
1456
1456
|
return `
|
|
1457
1457
|
function ${functionName}
|
package/dist/completion.js
CHANGED
|
@@ -1451,7 +1451,7 @@ const fish = {
|
|
|
1451
1451
|
name: "fish",
|
|
1452
1452
|
generateScript(programName, args = []) {
|
|
1453
1453
|
validateProgramName(programName);
|
|
1454
|
-
const escapedArgs = args.map((arg) => `'${arg.replace(/'/g, "\\'")}'`).join(" ");
|
|
1454
|
+
const escapedArgs = args.map((arg) => `'${arg.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`).join(" ");
|
|
1455
1455
|
const functionName = `__${programName}_complete`;
|
|
1456
1456
|
return `
|
|
1457
1457
|
function ${functionName}
|
package/dist/constructs.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_annotations = require('./internal/annotations.cjs');
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
|
+
const require_command_usage = require('./internal/command-usage.cjs');
|
|
3
4
|
const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
|
|
4
5
|
const require_passthrough = require('./internal/passthrough.cjs');
|
|
5
6
|
const require_validate = require('./validate.cjs');
|
|
@@ -382,10 +383,10 @@ function applyHiddenToUsageTerm(term, hidden) {
|
|
|
382
383
|
type: "exclusive",
|
|
383
384
|
terms: term.terms.map((u) => applyHiddenToUsage(u, hidden))
|
|
384
385
|
};
|
|
385
|
-
if (term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") return {
|
|
386
|
+
if (term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") return require_command_usage.copyCommandUsageId(term, {
|
|
386
387
|
...term,
|
|
387
388
|
hidden: require_usage.mergeHidden(term.hidden, hidden)
|
|
388
|
-
};
|
|
389
|
+
});
|
|
389
390
|
return term;
|
|
390
391
|
}
|
|
391
392
|
function applyHiddenToUsage(usage, hidden) {
|
|
@@ -1252,6 +1253,7 @@ function or(...args) {
|
|
|
1252
1253
|
success: false
|
|
1253
1254
|
};
|
|
1254
1255
|
};
|
|
1256
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
1255
1257
|
const singleResult = {
|
|
1256
1258
|
mode: combinedMode,
|
|
1257
1259
|
$valueType: [],
|
|
@@ -1259,7 +1261,7 @@ function or(...args) {
|
|
|
1259
1261
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
1260
1262
|
usage: [{
|
|
1261
1263
|
type: "exclusive",
|
|
1262
|
-
terms: parsers.map((p) => p.usage)
|
|
1264
|
+
terms: parsers.map((p, i) => require_command_usage.scopeCommandUsage(p.usage, commandUsageScopes[i]))
|
|
1263
1265
|
}],
|
|
1264
1266
|
leadingNames: unionLeadingNames(parsers),
|
|
1265
1267
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
@@ -1289,7 +1291,7 @@ function or(...args) {
|
|
|
1289
1291
|
state: parserResult.next.state
|
|
1290
1292
|
} : { kind: "unavailable" };
|
|
1291
1293
|
const docFragments = parsers[index].getDocFragments(innerState, void 0);
|
|
1292
|
-
commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docFragments);
|
|
1294
|
+
commandMetadata = require_command_doc_metadata.scopeCommandDocMetadata(require_command_doc_metadata.getCommandDocMetadata(docFragments), commandUsageScopes[index]);
|
|
1293
1295
|
brief = docFragments.brief;
|
|
1294
1296
|
description = docFragments.description;
|
|
1295
1297
|
footer = docFragments.footer;
|
|
@@ -1480,6 +1482,7 @@ function longestMatch(...args) {
|
|
|
1480
1482
|
success: false
|
|
1481
1483
|
};
|
|
1482
1484
|
};
|
|
1485
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
1483
1486
|
const multiResult = {
|
|
1484
1487
|
mode: combinedMode,
|
|
1485
1488
|
$valueType: [],
|
|
@@ -1487,7 +1490,7 @@ function longestMatch(...args) {
|
|
|
1487
1490
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
1488
1491
|
usage: [{
|
|
1489
1492
|
type: "exclusive",
|
|
1490
|
-
terms: parsers.map((p) => p.usage)
|
|
1493
|
+
terms: parsers.map((p, i) => require_command_usage.scopeCommandUsage(p.usage, commandUsageScopes[i]))
|
|
1491
1494
|
}],
|
|
1492
1495
|
leadingNames: unionLeadingNames(parsers),
|
|
1493
1496
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
@@ -1520,7 +1523,7 @@ function longestMatch(...args) {
|
|
|
1520
1523
|
kind: "available",
|
|
1521
1524
|
state: result.next.state
|
|
1522
1525
|
});
|
|
1523
|
-
commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docResult);
|
|
1526
|
+
commandMetadata = require_command_doc_metadata.scopeCommandDocMetadata(require_command_doc_metadata.getCommandDocMetadata(docResult), commandUsageScopes[i]);
|
|
1524
1527
|
brief = docResult.brief;
|
|
1525
1528
|
description = docResult.description;
|
|
1526
1529
|
footer = docResult.footer;
|
|
@@ -2231,13 +2234,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2231
2234
|
success: false
|
|
2232
2235
|
};
|
|
2233
2236
|
};
|
|
2237
|
+
const commandUsageScopes = new Map(parserPairs.map(([field]) => [field, /* @__PURE__ */ new WeakMap()]));
|
|
2234
2238
|
const objectParser = {
|
|
2235
2239
|
mode: combinedMode,
|
|
2236
2240
|
$valueType: [],
|
|
2237
2241
|
$stateType: [],
|
|
2238
2242
|
[fieldParsersKey]: parserPairs,
|
|
2239
2243
|
priority: Math.max(...parserKeys.map((k) => parsers[k].priority)),
|
|
2240
|
-
usage: applyHiddenToUsage(parserPairs.flatMap(([
|
|
2244
|
+
usage: applyHiddenToUsage(parserPairs.flatMap(([field, p]) => require_command_usage.scopeCommandUsage(p.usage, commandUsageScopes.get(field))), options.hidden),
|
|
2241
2245
|
leadingNames: sharedBufferLeadingNames(parserPairs.map(([_, p]) => p)),
|
|
2242
2246
|
acceptingAnyToken: parserPairs.some(([_, p]) => p.acceptingAnyToken),
|
|
2243
2247
|
get initialState() {
|
|
@@ -2489,7 +2493,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2489
2493
|
state: state.state[field]
|
|
2490
2494
|
};
|
|
2491
2495
|
const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
|
|
2492
|
-
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
|
|
2496
|
+
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs, false, commandUsageScopes.get(field));
|
|
2493
2497
|
return docs.fragments;
|
|
2494
2498
|
});
|
|
2495
2499
|
const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
|
|
@@ -2946,12 +2950,16 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2946
2950
|
consumed: allConsumed
|
|
2947
2951
|
};
|
|
2948
2952
|
};
|
|
2953
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
2949
2954
|
const tupleParser = {
|
|
2950
2955
|
mode: combinedMode,
|
|
2951
2956
|
$valueType: [],
|
|
2952
2957
|
$stateType: [],
|
|
2953
2958
|
[fieldParsersKey]: parsers.map((parser, index) => [String(index), parser]),
|
|
2954
|
-
usage: parsers.
|
|
2959
|
+
usage: parsers.map((p, i) => ({
|
|
2960
|
+
p,
|
|
2961
|
+
i
|
|
2962
|
+
})).toSorted((a, b) => b.p.priority - a.p.priority).flatMap(({ p, i }) => require_command_usage.scopeCommandUsage(p.usage, commandUsageScopes[i])),
|
|
2955
2963
|
leadingNames: sharedBufferLeadingNames(parsers),
|
|
2956
2964
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
2957
2965
|
priority: parsers.length > 0 ? Math.max(...parsers.map((p) => p.priority)) : 0,
|
|
@@ -3144,7 +3152,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3144
3152
|
state: state.state[i]
|
|
3145
3153
|
};
|
|
3146
3154
|
const docs = p.getDocFragments(indexState, defaultValue?.[i]);
|
|
3147
|
-
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
|
|
3155
|
+
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs, false, commandUsageScopes[i]);
|
|
3148
3156
|
return docs.fragments;
|
|
3149
3157
|
});
|
|
3150
3158
|
const entries = fragments.filter((d) => d.type === "entry");
|
|
@@ -3638,13 +3646,14 @@ function merge(...args) {
|
|
|
3638
3646
|
consumed: allConsumed
|
|
3639
3647
|
};
|
|
3640
3648
|
};
|
|
3649
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
3641
3650
|
const mergeParser = {
|
|
3642
3651
|
mode: combinedMode,
|
|
3643
3652
|
$valueType: [],
|
|
3644
3653
|
$stateType: [],
|
|
3645
3654
|
[fieldParsersKey]: mergedFieldParsers,
|
|
3646
3655
|
priority: Math.max(...mergeParseLanes.map((lane) => lane.priority)),
|
|
3647
|
-
usage: applyHiddenToUsage(parsers.flatMap((p) => p.usage), options.hidden),
|
|
3656
|
+
usage: applyHiddenToUsage(parsers.flatMap((p, i) => require_command_usage.scopeCommandUsage(p.usage, commandUsageScopes[i])), options.hidden),
|
|
3648
3657
|
leadingNames: sharedBufferLeadingNames(mergeParseLanes),
|
|
3649
3658
|
acceptingAnyToken: mergeParseLanes.some((lane) => lane.acceptingAnyToken),
|
|
3650
3659
|
initialState,
|
|
@@ -4073,7 +4082,7 @@ function merge(...args) {
|
|
|
4073
4082
|
state: state.state
|
|
4074
4083
|
};
|
|
4075
4084
|
const docFragments = p.getDocFragments(parserState, void 0);
|
|
4076
|
-
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docFragments, true);
|
|
4085
|
+
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docFragments, true, commandUsageScopes[i]);
|
|
4077
4086
|
brief ??= docFragments.brief;
|
|
4078
4087
|
description ??= docFragments.description;
|
|
4079
4088
|
footer ??= docFragments.footer;
|
|
@@ -4610,12 +4619,13 @@ function concat(...parsers) {
|
|
|
4610
4619
|
} : {}
|
|
4611
4620
|
};
|
|
4612
4621
|
};
|
|
4622
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
4613
4623
|
const concatParser = {
|
|
4614
4624
|
mode: combinedMode,
|
|
4615
4625
|
$valueType: [],
|
|
4616
4626
|
$stateType: [],
|
|
4617
4627
|
priority: parsers.length > 0 ? Math.max(...parsers.map((p) => p.priority)) : 0,
|
|
4618
|
-
usage: parsers.flatMap((p) => p.usage),
|
|
4628
|
+
usage: parsers.flatMap((p, i) => require_command_usage.scopeCommandUsage(p.usage, commandUsageScopes[i])),
|
|
4619
4629
|
leadingNames: sharedBufferLeadingNames(parsers),
|
|
4620
4630
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
4621
4631
|
initialState,
|
|
@@ -4733,7 +4743,7 @@ function concat(...parsers) {
|
|
|
4733
4743
|
state: state.state[index]
|
|
4734
4744
|
};
|
|
4735
4745
|
const docs = p.getDocFragments(indexState, void 0);
|
|
4736
|
-
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
|
|
4746
|
+
commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs, false, commandUsageScopes[index]);
|
|
4737
4747
|
return docs.fragments;
|
|
4738
4748
|
});
|
|
4739
4749
|
const entries = fragments.filter((f) => f.type === "entry");
|
|
@@ -4944,8 +4954,12 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
4944
4954
|
else result.push(term);
|
|
4945
4955
|
return result;
|
|
4946
4956
|
}
|
|
4947
|
-
const
|
|
4948
|
-
|
|
4957
|
+
const discriminatorUsageScope = /* @__PURE__ */ new WeakMap();
|
|
4958
|
+
const branchUsageScope = /* @__PURE__ */ new WeakMap();
|
|
4959
|
+
const commandUsageScopes = new Map(branchParsers.map(([key]) => [key, /* @__PURE__ */ new WeakMap()]));
|
|
4960
|
+
const defaultUsageScope = /* @__PURE__ */ new WeakMap();
|
|
4961
|
+
const branchUsages = branchParsers.map(([key, p]) => require_command_usage.scopeCommandUsage([...appendLiteralToUsage(require_command_usage.scopeCommandUsage(discriminator.usage, discriminatorUsageScope), key), ...require_command_usage.scopeCommandUsage(p.usage, branchUsageScope)], commandUsageScopes.get(key)));
|
|
4962
|
+
if (defaultBranch) branchUsages.push(require_command_usage.scopeCommandUsage(defaultBranch.usage, defaultUsageScope));
|
|
4949
4963
|
const usage = branchUsages.length > 1 ? [{
|
|
4950
4964
|
type: "exclusive",
|
|
4951
4965
|
terms: branchUsages
|
|
@@ -5795,7 +5809,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5795
5809
|
if (isAsync) return suggestAsync(context, prefix);
|
|
5796
5810
|
return suggestSync(context, prefix);
|
|
5797
5811
|
},
|
|
5798
|
-
getDocFragments(
|
|
5812
|
+
getDocFragments(state, _defaultValue) {
|
|
5799
5813
|
const fragments = [];
|
|
5800
5814
|
const discriminatorFragments = discriminator.getDocFragments({ kind: "unavailable" }, void 0);
|
|
5801
5815
|
fragments.push(...discriminatorFragments.fragments);
|
|
@@ -5819,7 +5833,27 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5819
5833
|
entries
|
|
5820
5834
|
});
|
|
5821
5835
|
}
|
|
5822
|
-
|
|
5836
|
+
let selected = require_command_doc_metadata.getSelectedCommandUsage(void 0);
|
|
5837
|
+
if (state.kind === "available" && state.state.selectedBranch != null) {
|
|
5838
|
+
const selection = state.state.selectedBranch;
|
|
5839
|
+
const branch = selection.kind === "default" ? defaultBranch : branches[selection.key];
|
|
5840
|
+
if (branch != null) {
|
|
5841
|
+
const docs = branch.getDocFragments({
|
|
5842
|
+
kind: "available",
|
|
5843
|
+
state: require_annotation_state.getWrappedChildState(state.state, state.state.branchState, branch)
|
|
5844
|
+
}, void 0);
|
|
5845
|
+
if (selection.kind === "default") selected = require_command_doc_metadata.getSelectedCommandUsage(require_command_doc_metadata.scopeCommandDocMetadata(require_command_doc_metadata.getCommandDocMetadata(docs), defaultUsageScope));
|
|
5846
|
+
else {
|
|
5847
|
+
const discriminatorDocs = discriminator.getDocFragments({
|
|
5848
|
+
kind: "available",
|
|
5849
|
+
state: require_annotation_state.getWrappedChildState(state.state, state.state.discriminatorState, discriminator)
|
|
5850
|
+
}, void 0);
|
|
5851
|
+
const metadata = require_command_doc_metadata.collectCommandDocMetadata(require_command_doc_metadata.scopeCommandDocMetadata(require_command_doc_metadata.getCommandDocMetadata(discriminatorDocs), discriminatorUsageScope), docs, false, branchUsageScope);
|
|
5852
|
+
selected = require_command_doc_metadata.getSelectedCommandUsage(require_command_doc_metadata.scopeCommandDocMetadata(metadata, commandUsageScopes.get(selection.key)));
|
|
5853
|
+
}
|
|
5854
|
+
}
|
|
5855
|
+
}
|
|
5856
|
+
return require_command_doc_metadata.withCommandDocMetadata({ fragments }, require_command_doc_metadata.withSelectedCommandUsage({}, selected));
|
|
5823
5857
|
}
|
|
5824
5858
|
};
|
|
5825
5859
|
require_parser.defineInheritedAnnotationParser(conditionalParser);
|
package/dist/constructs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { annotateFreshArray, getAnnotations, inheritAnnotations } from "./internal/annotations.js";
|
|
2
2
|
import { message, optionName, text, values } from "./message.js";
|
|
3
|
-
import {
|
|
3
|
+
import { copyCommandUsageId, scopeCommandUsage } from "./internal/command-usage.js";
|
|
4
|
+
import { collectCommandDocMetadata, getCommandDocMetadata, getSelectedCommandUsage, scopeCommandDocMetadata, withCommandDocMetadata, withSelectedCommandUsage } from "./internal/command-doc-metadata.js";
|
|
4
5
|
import { combineOptionMatches, combinePassThroughPriorities, defineOptionMatch, definePassThroughPriority, delegateKnownCompletion, getKnownCompletion, getOptionMatch, getPassThroughFailureHint, getPassThroughPriority, hasPassThroughUsage, matchesOptionToken, retainConsumingFailure, retainConsumingFailureHint, withPassThroughFailure } from "./internal/passthrough.js";
|
|
5
6
|
import { validateLabel } from "./validate.js";
|
|
6
7
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, isDocHidden, mergeHidden } from "./usage.js";
|
|
@@ -382,10 +383,10 @@ function applyHiddenToUsageTerm(term, hidden) {
|
|
|
382
383
|
type: "exclusive",
|
|
383
384
|
terms: term.terms.map((u) => applyHiddenToUsage(u, hidden))
|
|
384
385
|
};
|
|
385
|
-
if (term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") return {
|
|
386
|
+
if (term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") return copyCommandUsageId(term, {
|
|
386
387
|
...term,
|
|
387
388
|
hidden: mergeHidden(term.hidden, hidden)
|
|
388
|
-
};
|
|
389
|
+
});
|
|
389
390
|
return term;
|
|
390
391
|
}
|
|
391
392
|
function applyHiddenToUsage(usage, hidden) {
|
|
@@ -1252,6 +1253,7 @@ function or(...args) {
|
|
|
1252
1253
|
success: false
|
|
1253
1254
|
};
|
|
1254
1255
|
};
|
|
1256
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
1255
1257
|
const singleResult = {
|
|
1256
1258
|
mode: combinedMode,
|
|
1257
1259
|
$valueType: [],
|
|
@@ -1259,7 +1261,7 @@ function or(...args) {
|
|
|
1259
1261
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
1260
1262
|
usage: [{
|
|
1261
1263
|
type: "exclusive",
|
|
1262
|
-
terms: parsers.map((p) => p.usage)
|
|
1264
|
+
terms: parsers.map((p, i) => scopeCommandUsage(p.usage, commandUsageScopes[i]))
|
|
1263
1265
|
}],
|
|
1264
1266
|
leadingNames: unionLeadingNames(parsers),
|
|
1265
1267
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
@@ -1289,7 +1291,7 @@ function or(...args) {
|
|
|
1289
1291
|
state: parserResult.next.state
|
|
1290
1292
|
} : { kind: "unavailable" };
|
|
1291
1293
|
const docFragments = parsers[index].getDocFragments(innerState, void 0);
|
|
1292
|
-
commandMetadata = getCommandDocMetadata(docFragments);
|
|
1294
|
+
commandMetadata = scopeCommandDocMetadata(getCommandDocMetadata(docFragments), commandUsageScopes[index]);
|
|
1293
1295
|
brief = docFragments.brief;
|
|
1294
1296
|
description = docFragments.description;
|
|
1295
1297
|
footer = docFragments.footer;
|
|
@@ -1480,6 +1482,7 @@ function longestMatch(...args) {
|
|
|
1480
1482
|
success: false
|
|
1481
1483
|
};
|
|
1482
1484
|
};
|
|
1485
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
1483
1486
|
const multiResult = {
|
|
1484
1487
|
mode: combinedMode,
|
|
1485
1488
|
$valueType: [],
|
|
@@ -1487,7 +1490,7 @@ function longestMatch(...args) {
|
|
|
1487
1490
|
priority: Math.max(...parsers.map((p) => p.priority)),
|
|
1488
1491
|
usage: [{
|
|
1489
1492
|
type: "exclusive",
|
|
1490
|
-
terms: parsers.map((p) => p.usage)
|
|
1493
|
+
terms: parsers.map((p, i) => scopeCommandUsage(p.usage, commandUsageScopes[i]))
|
|
1491
1494
|
}],
|
|
1492
1495
|
leadingNames: unionLeadingNames(parsers),
|
|
1493
1496
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
@@ -1520,7 +1523,7 @@ function longestMatch(...args) {
|
|
|
1520
1523
|
kind: "available",
|
|
1521
1524
|
state: result.next.state
|
|
1522
1525
|
});
|
|
1523
|
-
commandMetadata = getCommandDocMetadata(docResult);
|
|
1526
|
+
commandMetadata = scopeCommandDocMetadata(getCommandDocMetadata(docResult), commandUsageScopes[i]);
|
|
1524
1527
|
brief = docResult.brief;
|
|
1525
1528
|
description = docResult.description;
|
|
1526
1529
|
footer = docResult.footer;
|
|
@@ -2231,13 +2234,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2231
2234
|
success: false
|
|
2232
2235
|
};
|
|
2233
2236
|
};
|
|
2237
|
+
const commandUsageScopes = new Map(parserPairs.map(([field]) => [field, /* @__PURE__ */ new WeakMap()]));
|
|
2234
2238
|
const objectParser = {
|
|
2235
2239
|
mode: combinedMode,
|
|
2236
2240
|
$valueType: [],
|
|
2237
2241
|
$stateType: [],
|
|
2238
2242
|
[fieldParsersKey]: parserPairs,
|
|
2239
2243
|
priority: Math.max(...parserKeys.map((k) => parsers[k].priority)),
|
|
2240
|
-
usage: applyHiddenToUsage(parserPairs.flatMap(([
|
|
2244
|
+
usage: applyHiddenToUsage(parserPairs.flatMap(([field, p]) => scopeCommandUsage(p.usage, commandUsageScopes.get(field))), options.hidden),
|
|
2241
2245
|
leadingNames: sharedBufferLeadingNames(parserPairs.map(([_, p]) => p)),
|
|
2242
2246
|
acceptingAnyToken: parserPairs.some(([_, p]) => p.acceptingAnyToken),
|
|
2243
2247
|
get initialState() {
|
|
@@ -2489,7 +2493,7 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2489
2493
|
state: state.state[field]
|
|
2490
2494
|
};
|
|
2491
2495
|
const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
|
|
2492
|
-
commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
|
|
2496
|
+
commandMetadata = collectCommandDocMetadata(commandMetadata, docs, false, commandUsageScopes.get(field));
|
|
2493
2497
|
return docs.fragments;
|
|
2494
2498
|
});
|
|
2495
2499
|
const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
|
|
@@ -2946,12 +2950,16 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
2946
2950
|
consumed: allConsumed
|
|
2947
2951
|
};
|
|
2948
2952
|
};
|
|
2953
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
2949
2954
|
const tupleParser = {
|
|
2950
2955
|
mode: combinedMode,
|
|
2951
2956
|
$valueType: [],
|
|
2952
2957
|
$stateType: [],
|
|
2953
2958
|
[fieldParsersKey]: parsers.map((parser, index) => [String(index), parser]),
|
|
2954
|
-
usage: parsers.
|
|
2959
|
+
usage: parsers.map((p, i) => ({
|
|
2960
|
+
p,
|
|
2961
|
+
i
|
|
2962
|
+
})).toSorted((a, b) => b.p.priority - a.p.priority).flatMap(({ p, i }) => scopeCommandUsage(p.usage, commandUsageScopes[i])),
|
|
2955
2963
|
leadingNames: sharedBufferLeadingNames(parsers),
|
|
2956
2964
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
2957
2965
|
priority: parsers.length > 0 ? Math.max(...parsers.map((p) => p.priority)) : 0,
|
|
@@ -3144,7 +3152,7 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
|
|
|
3144
3152
|
state: state.state[i]
|
|
3145
3153
|
};
|
|
3146
3154
|
const docs = p.getDocFragments(indexState, defaultValue?.[i]);
|
|
3147
|
-
commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
|
|
3155
|
+
commandMetadata = collectCommandDocMetadata(commandMetadata, docs, false, commandUsageScopes[i]);
|
|
3148
3156
|
return docs.fragments;
|
|
3149
3157
|
});
|
|
3150
3158
|
const entries = fragments.filter((d) => d.type === "entry");
|
|
@@ -3638,13 +3646,14 @@ function merge(...args) {
|
|
|
3638
3646
|
consumed: allConsumed
|
|
3639
3647
|
};
|
|
3640
3648
|
};
|
|
3649
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
3641
3650
|
const mergeParser = {
|
|
3642
3651
|
mode: combinedMode,
|
|
3643
3652
|
$valueType: [],
|
|
3644
3653
|
$stateType: [],
|
|
3645
3654
|
[fieldParsersKey]: mergedFieldParsers,
|
|
3646
3655
|
priority: Math.max(...mergeParseLanes.map((lane) => lane.priority)),
|
|
3647
|
-
usage: applyHiddenToUsage(parsers.flatMap((p) => p.usage), options.hidden),
|
|
3656
|
+
usage: applyHiddenToUsage(parsers.flatMap((p, i) => scopeCommandUsage(p.usage, commandUsageScopes[i])), options.hidden),
|
|
3648
3657
|
leadingNames: sharedBufferLeadingNames(mergeParseLanes),
|
|
3649
3658
|
acceptingAnyToken: mergeParseLanes.some((lane) => lane.acceptingAnyToken),
|
|
3650
3659
|
initialState,
|
|
@@ -4073,7 +4082,7 @@ function merge(...args) {
|
|
|
4073
4082
|
state: state.state
|
|
4074
4083
|
};
|
|
4075
4084
|
const docFragments = p.getDocFragments(parserState, void 0);
|
|
4076
|
-
commandMetadata = collectCommandDocMetadata(commandMetadata, docFragments, true);
|
|
4085
|
+
commandMetadata = collectCommandDocMetadata(commandMetadata, docFragments, true, commandUsageScopes[i]);
|
|
4077
4086
|
brief ??= docFragments.brief;
|
|
4078
4087
|
description ??= docFragments.description;
|
|
4079
4088
|
footer ??= docFragments.footer;
|
|
@@ -4610,12 +4619,13 @@ function concat(...parsers) {
|
|
|
4610
4619
|
} : {}
|
|
4611
4620
|
};
|
|
4612
4621
|
};
|
|
4622
|
+
const commandUsageScopes = parsers.map(() => /* @__PURE__ */ new WeakMap());
|
|
4613
4623
|
const concatParser = {
|
|
4614
4624
|
mode: combinedMode,
|
|
4615
4625
|
$valueType: [],
|
|
4616
4626
|
$stateType: [],
|
|
4617
4627
|
priority: parsers.length > 0 ? Math.max(...parsers.map((p) => p.priority)) : 0,
|
|
4618
|
-
usage: parsers.flatMap((p) => p.usage),
|
|
4628
|
+
usage: parsers.flatMap((p, i) => scopeCommandUsage(p.usage, commandUsageScopes[i])),
|
|
4619
4629
|
leadingNames: sharedBufferLeadingNames(parsers),
|
|
4620
4630
|
acceptingAnyToken: parsers.some((p) => p.acceptingAnyToken),
|
|
4621
4631
|
initialState,
|
|
@@ -4733,7 +4743,7 @@ function concat(...parsers) {
|
|
|
4733
4743
|
state: state.state[index]
|
|
4734
4744
|
};
|
|
4735
4745
|
const docs = p.getDocFragments(indexState, void 0);
|
|
4736
|
-
commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
|
|
4746
|
+
commandMetadata = collectCommandDocMetadata(commandMetadata, docs, false, commandUsageScopes[index]);
|
|
4737
4747
|
return docs.fragments;
|
|
4738
4748
|
});
|
|
4739
4749
|
const entries = fragments.filter((f) => f.type === "entry");
|
|
@@ -4944,8 +4954,12 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
4944
4954
|
else result.push(term);
|
|
4945
4955
|
return result;
|
|
4946
4956
|
}
|
|
4947
|
-
const
|
|
4948
|
-
|
|
4957
|
+
const discriminatorUsageScope = /* @__PURE__ */ new WeakMap();
|
|
4958
|
+
const branchUsageScope = /* @__PURE__ */ new WeakMap();
|
|
4959
|
+
const commandUsageScopes = new Map(branchParsers.map(([key]) => [key, /* @__PURE__ */ new WeakMap()]));
|
|
4960
|
+
const defaultUsageScope = /* @__PURE__ */ new WeakMap();
|
|
4961
|
+
const branchUsages = branchParsers.map(([key, p]) => scopeCommandUsage([...appendLiteralToUsage(scopeCommandUsage(discriminator.usage, discriminatorUsageScope), key), ...scopeCommandUsage(p.usage, branchUsageScope)], commandUsageScopes.get(key)));
|
|
4962
|
+
if (defaultBranch) branchUsages.push(scopeCommandUsage(defaultBranch.usage, defaultUsageScope));
|
|
4949
4963
|
const usage = branchUsages.length > 1 ? [{
|
|
4950
4964
|
type: "exclusive",
|
|
4951
4965
|
terms: branchUsages
|
|
@@ -5795,7 +5809,7 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5795
5809
|
if (isAsync) return suggestAsync(context, prefix);
|
|
5796
5810
|
return suggestSync(context, prefix);
|
|
5797
5811
|
},
|
|
5798
|
-
getDocFragments(
|
|
5812
|
+
getDocFragments(state, _defaultValue) {
|
|
5799
5813
|
const fragments = [];
|
|
5800
5814
|
const discriminatorFragments = discriminator.getDocFragments({ kind: "unavailable" }, void 0);
|
|
5801
5815
|
fragments.push(...discriminatorFragments.fragments);
|
|
@@ -5819,7 +5833,27 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
5819
5833
|
entries
|
|
5820
5834
|
});
|
|
5821
5835
|
}
|
|
5822
|
-
|
|
5836
|
+
let selected = getSelectedCommandUsage(void 0);
|
|
5837
|
+
if (state.kind === "available" && state.state.selectedBranch != null) {
|
|
5838
|
+
const selection = state.state.selectedBranch;
|
|
5839
|
+
const branch = selection.kind === "default" ? defaultBranch : branches[selection.key];
|
|
5840
|
+
if (branch != null) {
|
|
5841
|
+
const docs = branch.getDocFragments({
|
|
5842
|
+
kind: "available",
|
|
5843
|
+
state: getWrappedChildState(state.state, state.state.branchState, branch)
|
|
5844
|
+
}, void 0);
|
|
5845
|
+
if (selection.kind === "default") selected = getSelectedCommandUsage(scopeCommandDocMetadata(getCommandDocMetadata(docs), defaultUsageScope));
|
|
5846
|
+
else {
|
|
5847
|
+
const discriminatorDocs = discriminator.getDocFragments({
|
|
5848
|
+
kind: "available",
|
|
5849
|
+
state: getWrappedChildState(state.state, state.state.discriminatorState, discriminator)
|
|
5850
|
+
}, void 0);
|
|
5851
|
+
const metadata = collectCommandDocMetadata(scopeCommandDocMetadata(getCommandDocMetadata(discriminatorDocs), discriminatorUsageScope), docs, false, branchUsageScope);
|
|
5852
|
+
selected = getSelectedCommandUsage(scopeCommandDocMetadata(metadata, commandUsageScopes.get(selection.key)));
|
|
5853
|
+
}
|
|
5854
|
+
}
|
|
5855
|
+
}
|
|
5856
|
+
return withCommandDocMetadata({ fragments }, withSelectedCommandUsage({}, selected));
|
|
5823
5857
|
}
|
|
5824
5858
|
};
|
|
5825
5859
|
defineInheritedAnnotationParser(conditionalParser);
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
const require_command_usage = require('./command-usage.cjs');
|
|
1
2
|
|
|
2
3
|
//#region src/internal/command-doc-metadata.ts
|
|
4
|
+
const selectedCommandUsage = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
/** Reads command occurrences selected by final parser state. @internal */
|
|
6
|
+
function getSelectedCommandUsage(metadata) {
|
|
7
|
+
return metadata == null ? [] : selectedCommandUsage.get(metadata) ?? [];
|
|
8
|
+
}
|
|
9
|
+
/** Attaches selection without adding public metadata properties. @internal */
|
|
10
|
+
function withSelectedCommandUsage(metadata, selected) {
|
|
11
|
+
const result = withOrigin(metadata ?? {}, metadata?.origin ?? "entry");
|
|
12
|
+
selectedCommandUsage.set(result, selected);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
/** Maps selected commands to the same child scope as its usage. @internal */
|
|
16
|
+
function scopeCommandDocMetadata(metadata, scope) {
|
|
17
|
+
return metadata == null ? void 0 : withSelectedCommandUsage(metadata, getSelectedCommandUsage(metadata).map((id) => require_command_usage.scopeCommandUsageId(scope, id)));
|
|
18
|
+
}
|
|
3
19
|
function withOrigin(metadata, origin) {
|
|
4
20
|
const result = { ...metadata };
|
|
21
|
+
selectedCommandUsage.set(result, getSelectedCommandUsage(metadata));
|
|
5
22
|
Object.defineProperty(result, "origin", {
|
|
6
23
|
value: origin,
|
|
7
24
|
enumerable: false
|
|
@@ -23,11 +40,11 @@ function getCommandDocMetadata(docs) {
|
|
|
23
40
|
const customPage = origin === "entry" && (docs.brief !== carrier.brief || docs.footer !== carrier.footer);
|
|
24
41
|
const description = origin === "entry" && !customPage || docs.description === carrier.description ? carrier.metadata.description : docs.description;
|
|
25
42
|
const footer = docs.footer === carrier.footer ? carrier.metadata.footer : docs.footer;
|
|
26
|
-
return withOrigin({
|
|
43
|
+
return withSelectedCommandUsage(withOrigin({
|
|
27
44
|
...brief == null ? {} : { brief },
|
|
28
45
|
...description == null ? {} : { description },
|
|
29
46
|
...footer == null ? {} : { footer }
|
|
30
|
-
}, customPage ? "custom" : origin);
|
|
47
|
+
}, customPage ? "custom" : origin), getSelectedCommandUsage(carrier.metadata));
|
|
31
48
|
}
|
|
32
49
|
const metadata = docs[commandDocMetadata];
|
|
33
50
|
if (metadata != null) return metadata;
|
|
@@ -67,7 +84,7 @@ function withCommandDocMetadata(docs, metadata) {
|
|
|
67
84
|
* @param includeCustom Whether to retain custom page fields inside merge().
|
|
68
85
|
* @returns The first defined value from children with the same origin.
|
|
69
86
|
*/
|
|
70
|
-
function
|
|
87
|
+
function collectCommandPageMetadata(current, docs, includeCustom = false) {
|
|
71
88
|
const next = getCommandDocMetadata(docs);
|
|
72
89
|
if (next == null) return current;
|
|
73
90
|
const origin = next.origin ?? "entry";
|
|
@@ -83,8 +100,19 @@ function collectCommandDocMetadata(current, docs, includeCustom = false) {
|
|
|
83
100
|
...footer == null ? {} : { footer }
|
|
84
101
|
}, origin);
|
|
85
102
|
}
|
|
103
|
+
/** Collects page fields and all selected command occurrences. @internal */
|
|
104
|
+
function collectCommandDocMetadata(current, docs, includeCustom = false, scope) {
|
|
105
|
+
const next = getCommandDocMetadata(docs);
|
|
106
|
+
const selected = getSelectedCommandUsage(next);
|
|
107
|
+
const result = collectCommandPageMetadata(current, docs, includeCustom);
|
|
108
|
+
const combined = [...getSelectedCommandUsage(current), ...scope == null ? selected : selected.map((id) => require_command_usage.scopeCommandUsageId(scope, id))];
|
|
109
|
+
return combined.length === 0 ? result : withSelectedCommandUsage(result, combined);
|
|
110
|
+
}
|
|
86
111
|
|
|
87
112
|
//#endregion
|
|
88
113
|
exports.collectCommandDocMetadata = collectCommandDocMetadata;
|
|
89
114
|
exports.getCommandDocMetadata = getCommandDocMetadata;
|
|
90
|
-
exports.
|
|
115
|
+
exports.getSelectedCommandUsage = getSelectedCommandUsage;
|
|
116
|
+
exports.scopeCommandDocMetadata = scopeCommandDocMetadata;
|
|
117
|
+
exports.withCommandDocMetadata = withCommandDocMetadata;
|
|
118
|
+
exports.withSelectedCommandUsage = withSelectedCommandUsage;
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
+
import { scopeCommandUsageId } from "./command-usage.js";
|
|
2
|
+
|
|
1
3
|
//#region src/internal/command-doc-metadata.ts
|
|
4
|
+
const selectedCommandUsage = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
/** Reads command occurrences selected by final parser state. @internal */
|
|
6
|
+
function getSelectedCommandUsage(metadata) {
|
|
7
|
+
return metadata == null ? [] : selectedCommandUsage.get(metadata) ?? [];
|
|
8
|
+
}
|
|
9
|
+
/** Attaches selection without adding public metadata properties. @internal */
|
|
10
|
+
function withSelectedCommandUsage(metadata, selected) {
|
|
11
|
+
const result = withOrigin(metadata ?? {}, metadata?.origin ?? "entry");
|
|
12
|
+
selectedCommandUsage.set(result, selected);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
/** Maps selected commands to the same child scope as its usage. @internal */
|
|
16
|
+
function scopeCommandDocMetadata(metadata, scope) {
|
|
17
|
+
return metadata == null ? void 0 : withSelectedCommandUsage(metadata, getSelectedCommandUsage(metadata).map((id) => scopeCommandUsageId(scope, id)));
|
|
18
|
+
}
|
|
2
19
|
function withOrigin(metadata, origin) {
|
|
3
20
|
const result = { ...metadata };
|
|
21
|
+
selectedCommandUsage.set(result, getSelectedCommandUsage(metadata));
|
|
4
22
|
Object.defineProperty(result, "origin", {
|
|
5
23
|
value: origin,
|
|
6
24
|
enumerable: false
|
|
@@ -22,11 +40,11 @@ function getCommandDocMetadata(docs) {
|
|
|
22
40
|
const customPage = origin === "entry" && (docs.brief !== carrier.brief || docs.footer !== carrier.footer);
|
|
23
41
|
const description = origin === "entry" && !customPage || docs.description === carrier.description ? carrier.metadata.description : docs.description;
|
|
24
42
|
const footer = docs.footer === carrier.footer ? carrier.metadata.footer : docs.footer;
|
|
25
|
-
return withOrigin({
|
|
43
|
+
return withSelectedCommandUsage(withOrigin({
|
|
26
44
|
...brief == null ? {} : { brief },
|
|
27
45
|
...description == null ? {} : { description },
|
|
28
46
|
...footer == null ? {} : { footer }
|
|
29
|
-
}, customPage ? "custom" : origin);
|
|
47
|
+
}, customPage ? "custom" : origin), getSelectedCommandUsage(carrier.metadata));
|
|
30
48
|
}
|
|
31
49
|
const metadata = docs[commandDocMetadata];
|
|
32
50
|
if (metadata != null) return metadata;
|
|
@@ -66,7 +84,7 @@ function withCommandDocMetadata(docs, metadata) {
|
|
|
66
84
|
* @param includeCustom Whether to retain custom page fields inside merge().
|
|
67
85
|
* @returns The first defined value from children with the same origin.
|
|
68
86
|
*/
|
|
69
|
-
function
|
|
87
|
+
function collectCommandPageMetadata(current, docs, includeCustom = false) {
|
|
70
88
|
const next = getCommandDocMetadata(docs);
|
|
71
89
|
if (next == null) return current;
|
|
72
90
|
const origin = next.origin ?? "entry";
|
|
@@ -82,6 +100,14 @@ function collectCommandDocMetadata(current, docs, includeCustom = false) {
|
|
|
82
100
|
...footer == null ? {} : { footer }
|
|
83
101
|
}, origin);
|
|
84
102
|
}
|
|
103
|
+
/** Collects page fields and all selected command occurrences. @internal */
|
|
104
|
+
function collectCommandDocMetadata(current, docs, includeCustom = false, scope) {
|
|
105
|
+
const next = getCommandDocMetadata(docs);
|
|
106
|
+
const selected = getSelectedCommandUsage(next);
|
|
107
|
+
const result = collectCommandPageMetadata(current, docs, includeCustom);
|
|
108
|
+
const combined = [...getSelectedCommandUsage(current), ...scope == null ? selected : selected.map((id) => scopeCommandUsageId(scope, id))];
|
|
109
|
+
return combined.length === 0 ? result : withSelectedCommandUsage(result, combined);
|
|
110
|
+
}
|
|
85
111
|
|
|
86
112
|
//#endregion
|
|
87
|
-
export { collectCommandDocMetadata, getCommandDocMetadata, withCommandDocMetadata };
|
|
113
|
+
export { collectCommandDocMetadata, getCommandDocMetadata, getSelectedCommandUsage, scopeCommandDocMetadata, withCommandDocMetadata, withSelectedCommandUsage };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/internal/command-usage.ts
|
|
3
|
+
const commandUsageIds = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
/** Associates a command usage leaf with its parser occurrence. @internal */
|
|
5
|
+
function identifyCommandUsage(term, id) {
|
|
6
|
+
commandUsageIds.set(term, id);
|
|
7
|
+
return term;
|
|
8
|
+
}
|
|
9
|
+
/** Reads a command usage leaf's private identity. @internal */
|
|
10
|
+
function getCommandUsageId(term) {
|
|
11
|
+
return commandUsageIds.get(term);
|
|
12
|
+
}
|
|
13
|
+
/** Preserves private identity when cloning a usage leaf. @internal */
|
|
14
|
+
function copyCommandUsageId(source, target) {
|
|
15
|
+
const id = commandUsageIds.get(source);
|
|
16
|
+
if (id != null) commandUsageIds.set(target, id);
|
|
17
|
+
return target;
|
|
18
|
+
}
|
|
19
|
+
/** Distinguishes repeated uses of one parser in different children. @internal */
|
|
20
|
+
function scopeCommandUsageId(scope, id) {
|
|
21
|
+
let scoped = scope.get(id);
|
|
22
|
+
if (scoped == null) {
|
|
23
|
+
scoped = {};
|
|
24
|
+
scope.set(id, scoped);
|
|
25
|
+
}
|
|
26
|
+
return scoped;
|
|
27
|
+
}
|
|
28
|
+
/** Copies usage with identities scoped to this child occurrence. @internal */
|
|
29
|
+
function scopeCommandUsage(usage, scope) {
|
|
30
|
+
return usage.map((term) => {
|
|
31
|
+
if (term.type === "command") {
|
|
32
|
+
const id = getCommandUsageId(term);
|
|
33
|
+
return id == null ? term : identifyCommandUsage({ ...term }, scopeCommandUsageId(scope, id));
|
|
34
|
+
}
|
|
35
|
+
if (term.type === "optional" || term.type === "multiple") return {
|
|
36
|
+
...term,
|
|
37
|
+
terms: scopeCommandUsage(term.terms, scope)
|
|
38
|
+
};
|
|
39
|
+
if (term.type === "exclusive") return {
|
|
40
|
+
...term,
|
|
41
|
+
terms: term.terms.map((branch) => scopeCommandUsage(branch, scope))
|
|
42
|
+
};
|
|
43
|
+
return term;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.copyCommandUsageId = copyCommandUsageId;
|
|
49
|
+
exports.getCommandUsageId = getCommandUsageId;
|
|
50
|
+
exports.identifyCommandUsage = identifyCommandUsage;
|
|
51
|
+
exports.scopeCommandUsage = scopeCommandUsage;
|
|
52
|
+
exports.scopeCommandUsageId = scopeCommandUsageId;
|