@optique/core 1.1.0 → 1.2.0-dev.2169
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/internal/parser.cjs +58 -1
- package/dist/internal/parser.js +58 -1
- package/package.json +2 -2
package/dist/internal/parser.cjs
CHANGED
|
@@ -784,13 +784,70 @@ function buildDocPage(parser, context, args, matchedCommandArgIndices) {
|
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
786
|
return {
|
|
787
|
-
usage,
|
|
787
|
+
usage: revealMatchedCommandUsage(usage, effectiveArgs, commandArgIndices ?? null),
|
|
788
788
|
sections,
|
|
789
789
|
...brief != null && { brief: require_message.cloneMessage(brief) },
|
|
790
790
|
...description != null && { description: require_message.cloneMessage(description) },
|
|
791
791
|
...footer != null && { footer: require_message.cloneMessage(footer) }
|
|
792
792
|
};
|
|
793
793
|
}
|
|
794
|
+
function revealMatchedCommandUsage(usage, args, matchedCommandArgIndices) {
|
|
795
|
+
if (args.length < 1) return usage;
|
|
796
|
+
const [revealed] = revealMatchedCommandUsageTerms(usage, args, matchedCommandArgIndices, 0);
|
|
797
|
+
return revealed;
|
|
798
|
+
}
|
|
799
|
+
function revealMatchedCommandUsageTerms(usage, args, matchedCommandArgIndices, argIndex) {
|
|
800
|
+
const terms = [];
|
|
801
|
+
let nextArgIndex = argIndex;
|
|
802
|
+
for (const term of usage) {
|
|
803
|
+
const [revealed, afterTermArgIndex] = revealMatchedCommandUsageTerm(term, args, matchedCommandArgIndices, nextArgIndex);
|
|
804
|
+
terms.push(revealed);
|
|
805
|
+
nextArgIndex = afterTermArgIndex;
|
|
806
|
+
}
|
|
807
|
+
return [terms, nextArgIndex];
|
|
808
|
+
}
|
|
809
|
+
function revealMatchedCommandUsageTerm(term, args, matchedCommandArgIndices, argIndex) {
|
|
810
|
+
if (term.type === "command") {
|
|
811
|
+
const nextArgIndex = findNextMatchedCommandArgIndex(args, matchedCommandArgIndices, argIndex);
|
|
812
|
+
if (nextArgIndex < args.length && commandTermMatches(term, args[nextArgIndex])) {
|
|
813
|
+
const { hidden: _hidden,...revealed } = term;
|
|
814
|
+
return [revealed, nextArgIndex + 1];
|
|
815
|
+
}
|
|
816
|
+
return [term, argIndex];
|
|
817
|
+
}
|
|
818
|
+
if (term.type === "sequence") {
|
|
819
|
+
const [terms, nextArgIndex] = revealMatchedCommandUsageTerms(term.terms, args, matchedCommandArgIndices, argIndex);
|
|
820
|
+
return [{
|
|
821
|
+
...term,
|
|
822
|
+
terms
|
|
823
|
+
}, nextArgIndex];
|
|
824
|
+
}
|
|
825
|
+
if (term.type === "optional" || term.type === "multiple") {
|
|
826
|
+
const [terms, nextArgIndex] = revealMatchedCommandUsageTerms(term.terms, args, matchedCommandArgIndices, argIndex);
|
|
827
|
+
return [{
|
|
828
|
+
...term,
|
|
829
|
+
terms
|
|
830
|
+
}, nextArgIndex];
|
|
831
|
+
}
|
|
832
|
+
if (term.type === "exclusive") {
|
|
833
|
+
let maxArgIndex = argIndex;
|
|
834
|
+
const terms = term.terms.map((branch) => {
|
|
835
|
+
const [revealed, nextArgIndex] = revealMatchedCommandUsageTerms(branch, args, matchedCommandArgIndices, argIndex);
|
|
836
|
+
if (nextArgIndex > maxArgIndex) maxArgIndex = nextArgIndex;
|
|
837
|
+
return revealed;
|
|
838
|
+
});
|
|
839
|
+
return [{
|
|
840
|
+
...term,
|
|
841
|
+
terms
|
|
842
|
+
}, maxArgIndex];
|
|
843
|
+
}
|
|
844
|
+
return [term, argIndex];
|
|
845
|
+
}
|
|
846
|
+
function findNextMatchedCommandArgIndex(args, matchedCommandArgIndices, start) {
|
|
847
|
+
if (matchedCommandArgIndices == null) return start;
|
|
848
|
+
for (let index = start; index < args.length; index++) if (matchedCommandArgIndices.has(index)) return index;
|
|
849
|
+
return args.length;
|
|
850
|
+
}
|
|
794
851
|
|
|
795
852
|
//#endregion
|
|
796
853
|
exports.annotationWrapperRequiresSourceBindingKey = annotationWrapperRequiresSourceBindingKey;
|
package/dist/internal/parser.js
CHANGED
|
@@ -784,13 +784,70 @@ function buildDocPage(parser, context, args, matchedCommandArgIndices) {
|
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
786
|
return {
|
|
787
|
-
usage,
|
|
787
|
+
usage: revealMatchedCommandUsage(usage, effectiveArgs, commandArgIndices ?? null),
|
|
788
788
|
sections,
|
|
789
789
|
...brief != null && { brief: cloneMessage(brief) },
|
|
790
790
|
...description != null && { description: cloneMessage(description) },
|
|
791
791
|
...footer != null && { footer: cloneMessage(footer) }
|
|
792
792
|
};
|
|
793
793
|
}
|
|
794
|
+
function revealMatchedCommandUsage(usage, args, matchedCommandArgIndices) {
|
|
795
|
+
if (args.length < 1) return usage;
|
|
796
|
+
const [revealed] = revealMatchedCommandUsageTerms(usage, args, matchedCommandArgIndices, 0);
|
|
797
|
+
return revealed;
|
|
798
|
+
}
|
|
799
|
+
function revealMatchedCommandUsageTerms(usage, args, matchedCommandArgIndices, argIndex) {
|
|
800
|
+
const terms = [];
|
|
801
|
+
let nextArgIndex = argIndex;
|
|
802
|
+
for (const term of usage) {
|
|
803
|
+
const [revealed, afterTermArgIndex] = revealMatchedCommandUsageTerm(term, args, matchedCommandArgIndices, nextArgIndex);
|
|
804
|
+
terms.push(revealed);
|
|
805
|
+
nextArgIndex = afterTermArgIndex;
|
|
806
|
+
}
|
|
807
|
+
return [terms, nextArgIndex];
|
|
808
|
+
}
|
|
809
|
+
function revealMatchedCommandUsageTerm(term, args, matchedCommandArgIndices, argIndex) {
|
|
810
|
+
if (term.type === "command") {
|
|
811
|
+
const nextArgIndex = findNextMatchedCommandArgIndex(args, matchedCommandArgIndices, argIndex);
|
|
812
|
+
if (nextArgIndex < args.length && commandTermMatches(term, args[nextArgIndex])) {
|
|
813
|
+
const { hidden: _hidden,...revealed } = term;
|
|
814
|
+
return [revealed, nextArgIndex + 1];
|
|
815
|
+
}
|
|
816
|
+
return [term, argIndex];
|
|
817
|
+
}
|
|
818
|
+
if (term.type === "sequence") {
|
|
819
|
+
const [terms, nextArgIndex] = revealMatchedCommandUsageTerms(term.terms, args, matchedCommandArgIndices, argIndex);
|
|
820
|
+
return [{
|
|
821
|
+
...term,
|
|
822
|
+
terms
|
|
823
|
+
}, nextArgIndex];
|
|
824
|
+
}
|
|
825
|
+
if (term.type === "optional" || term.type === "multiple") {
|
|
826
|
+
const [terms, nextArgIndex] = revealMatchedCommandUsageTerms(term.terms, args, matchedCommandArgIndices, argIndex);
|
|
827
|
+
return [{
|
|
828
|
+
...term,
|
|
829
|
+
terms
|
|
830
|
+
}, nextArgIndex];
|
|
831
|
+
}
|
|
832
|
+
if (term.type === "exclusive") {
|
|
833
|
+
let maxArgIndex = argIndex;
|
|
834
|
+
const terms = term.terms.map((branch) => {
|
|
835
|
+
const [revealed, nextArgIndex] = revealMatchedCommandUsageTerms(branch, args, matchedCommandArgIndices, argIndex);
|
|
836
|
+
if (nextArgIndex > maxArgIndex) maxArgIndex = nextArgIndex;
|
|
837
|
+
return revealed;
|
|
838
|
+
});
|
|
839
|
+
return [{
|
|
840
|
+
...term,
|
|
841
|
+
terms
|
|
842
|
+
}, maxArgIndex];
|
|
843
|
+
}
|
|
844
|
+
return [term, argIndex];
|
|
845
|
+
}
|
|
846
|
+
function findNextMatchedCommandArgIndex(args, matchedCommandArgIndices, start) {
|
|
847
|
+
if (matchedCommandArgIndices == null) return start;
|
|
848
|
+
for (let index = start; index < args.length; index++) if (matchedCommandArgIndices.has(index)) return index;
|
|
849
|
+
return args.length;
|
|
850
|
+
}
|
|
794
851
|
|
|
795
852
|
//#endregion
|
|
796
853
|
export { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, createParserContext, defineInheritedAnnotationParser, defineSourceBindingOnlyAnnotationCompletionParser, getDelegatingSuggestRuntimeNodes, getDocPage, getDocPageAsync, getDocPageSync, getParserSuggestRuntimeNodes, inheritParentAnnotationsKey, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync, unmatchedNonCliDependencySourceStateMarker };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-dev.2169",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
"fast-check": "^4.7.0",
|
|
201
201
|
"tsdown": "^0.13.0",
|
|
202
202
|
"typescript": "^5.8.3",
|
|
203
|
-
"@optique/env": "1.
|
|
203
|
+
"@optique/env": "1.2.0-dev.2169+209bc0fc"
|
|
204
204
|
},
|
|
205
205
|
"scripts": {
|
|
206
206
|
"build": "tsdown",
|