@optique/core 1.0.0-dev.1323 → 1.0.0-dev.1335
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 +14 -18
- package/dist/constructs.js +14 -18
- package/dist/doc.cjs +115 -0
- package/dist/doc.d.cts +35 -1
- package/dist/doc.d.ts +35 -1
- package/dist/doc.js +115 -3
- package/dist/facade.cjs +1 -1
- package/dist/facade.js +1 -1
- package/dist/index.cjs +6 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/message.cjs +40 -0
- package/dist/message.d.cts +21 -1
- package/dist/message.d.ts +21 -1
- package/dist/message.js +39 -1
- package/dist/parser.cjs +13 -11
- package/dist/parser.js +15 -13
- package/dist/usage.cjs +55 -0
- package/dist/usage.d.cts +21 -1
- package/dist/usage.d.ts +21 -1
- package/dist/usage.js +54 -1
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -3,6 +3,7 @@ const require_message = require('./message.cjs');
|
|
|
3
3
|
const require_dependency = require('./dependency.cjs');
|
|
4
4
|
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
5
5
|
const require_usage = require('./usage.cjs');
|
|
6
|
+
const require_doc = require('./doc.cjs');
|
|
6
7
|
const require_suggestion = require('./suggestion.cjs');
|
|
7
8
|
const require_usage_internals = require('./usage-internals.cjs');
|
|
8
9
|
|
|
@@ -471,24 +472,12 @@ function or(...args) {
|
|
|
471
472
|
footer = docFragments.footer;
|
|
472
473
|
fragments = docFragments.fragments;
|
|
473
474
|
}
|
|
474
|
-
|
|
475
|
-
const sections = [];
|
|
476
|
-
for (const fragment of fragments) {
|
|
477
|
-
if (fragment.type !== "section") continue;
|
|
478
|
-
if (fragment.title == null) entries.push(...fragment.entries);
|
|
479
|
-
else sections.push(fragment);
|
|
480
|
-
}
|
|
475
|
+
if (state.kind === "unavailable" || state.state == null) fragments = require_doc.deduplicateDocFragments(fragments);
|
|
481
476
|
return {
|
|
482
477
|
brief,
|
|
483
478
|
description,
|
|
484
479
|
footer,
|
|
485
|
-
fragments
|
|
486
|
-
...s,
|
|
487
|
-
type: "section"
|
|
488
|
-
})), {
|
|
489
|
-
type: "section",
|
|
490
|
-
entries
|
|
491
|
-
}]
|
|
480
|
+
fragments
|
|
492
481
|
};
|
|
493
482
|
}
|
|
494
483
|
};
|
|
@@ -606,8 +595,11 @@ function longestMatch(...args) {
|
|
|
606
595
|
let description;
|
|
607
596
|
let footer;
|
|
608
597
|
let fragments;
|
|
609
|
-
|
|
610
|
-
|
|
598
|
+
let shouldDeduplicate;
|
|
599
|
+
if (state.kind === "unavailable" || state.state == null) {
|
|
600
|
+
fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
|
|
601
|
+
shouldDeduplicate = true;
|
|
602
|
+
} else {
|
|
611
603
|
const [i, result] = state.state;
|
|
612
604
|
if (result.success) {
|
|
613
605
|
const docResult = parsers[i].getDocFragments({
|
|
@@ -618,12 +610,16 @@ function longestMatch(...args) {
|
|
|
618
610
|
description = docResult.description;
|
|
619
611
|
footer = docResult.footer;
|
|
620
612
|
fragments = docResult.fragments;
|
|
621
|
-
|
|
613
|
+
shouldDeduplicate = false;
|
|
614
|
+
} else {
|
|
615
|
+
fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
|
|
616
|
+
shouldDeduplicate = true;
|
|
617
|
+
}
|
|
622
618
|
}
|
|
623
619
|
return {
|
|
624
620
|
brief,
|
|
625
621
|
description,
|
|
626
|
-
fragments,
|
|
622
|
+
fragments: shouldDeduplicate ? require_doc.deduplicateDocFragments(fragments) : fragments,
|
|
627
623
|
footer
|
|
628
624
|
};
|
|
629
625
|
}
|
package/dist/constructs.js
CHANGED
|
@@ -3,6 +3,7 @@ import { message, optionName, text, values } from "./message.js";
|
|
|
3
3
|
import { DependencyRegistry, createDependencySourceState, dependencyId, isDeferredParseState, isDependencySourceState, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, wrappedDependencySourceMarker } from "./dependency.js";
|
|
4
4
|
import { dispatchByMode, dispatchIterableByMode } from "./mode-dispatch.js";
|
|
5
5
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, isDocHidden, mergeHidden } from "./usage.js";
|
|
6
|
+
import { deduplicateDocFragments } from "./doc.js";
|
|
6
7
|
import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, deduplicateSuggestions, findSimilar } from "./suggestion.js";
|
|
7
8
|
import { collectLeadingCandidates } from "./usage-internals.js";
|
|
8
9
|
|
|
@@ -471,24 +472,12 @@ function or(...args) {
|
|
|
471
472
|
footer = docFragments.footer;
|
|
472
473
|
fragments = docFragments.fragments;
|
|
473
474
|
}
|
|
474
|
-
|
|
475
|
-
const sections = [];
|
|
476
|
-
for (const fragment of fragments) {
|
|
477
|
-
if (fragment.type !== "section") continue;
|
|
478
|
-
if (fragment.title == null) entries.push(...fragment.entries);
|
|
479
|
-
else sections.push(fragment);
|
|
480
|
-
}
|
|
475
|
+
if (state.kind === "unavailable" || state.state == null) fragments = deduplicateDocFragments(fragments);
|
|
481
476
|
return {
|
|
482
477
|
brief,
|
|
483
478
|
description,
|
|
484
479
|
footer,
|
|
485
|
-
fragments
|
|
486
|
-
...s,
|
|
487
|
-
type: "section"
|
|
488
|
-
})), {
|
|
489
|
-
type: "section",
|
|
490
|
-
entries
|
|
491
|
-
}]
|
|
480
|
+
fragments
|
|
492
481
|
};
|
|
493
482
|
}
|
|
494
483
|
};
|
|
@@ -606,8 +595,11 @@ function longestMatch(...args) {
|
|
|
606
595
|
let description;
|
|
607
596
|
let footer;
|
|
608
597
|
let fragments;
|
|
609
|
-
|
|
610
|
-
|
|
598
|
+
let shouldDeduplicate;
|
|
599
|
+
if (state.kind === "unavailable" || state.state == null) {
|
|
600
|
+
fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
|
|
601
|
+
shouldDeduplicate = true;
|
|
602
|
+
} else {
|
|
611
603
|
const [i, result] = state.state;
|
|
612
604
|
if (result.success) {
|
|
613
605
|
const docResult = parsers[i].getDocFragments({
|
|
@@ -618,12 +610,16 @@ function longestMatch(...args) {
|
|
|
618
610
|
description = docResult.description;
|
|
619
611
|
footer = docResult.footer;
|
|
620
612
|
fragments = docResult.fragments;
|
|
621
|
-
|
|
613
|
+
shouldDeduplicate = false;
|
|
614
|
+
} else {
|
|
615
|
+
fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
|
|
616
|
+
shouldDeduplicate = true;
|
|
617
|
+
}
|
|
622
618
|
}
|
|
623
619
|
return {
|
|
624
620
|
brief,
|
|
625
621
|
description,
|
|
626
|
-
fragments,
|
|
622
|
+
fragments: shouldDeduplicate ? deduplicateDocFragments(fragments) : fragments,
|
|
627
623
|
footer
|
|
628
624
|
};
|
|
629
625
|
}
|
package/dist/doc.cjs
CHANGED
|
@@ -2,6 +2,118 @@ const require_message = require('./message.cjs');
|
|
|
2
2
|
const require_usage = require('./usage.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/doc.ts
|
|
5
|
+
function getDocEntryKey(entry) {
|
|
6
|
+
const term = entry.term;
|
|
7
|
+
switch (term.type) {
|
|
8
|
+
case "command": return `command:${term.name}`;
|
|
9
|
+
case "option": return `option:${[...term.names].sort().join(",")}:${term.metavar ?? ""}`;
|
|
10
|
+
case "argument": return `argument:${term.metavar}`;
|
|
11
|
+
default: return JSON.stringify(term);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Removes duplicate {@link DocEntry} values that share the same surface
|
|
16
|
+
* syntax (same term type and identifying names). When duplicates exist,
|
|
17
|
+
* the first occurrence is kept and later ones are discarded.
|
|
18
|
+
*
|
|
19
|
+
* Positional argument entries are never deduplicated because they are
|
|
20
|
+
* distinguished by position, not by metavar, and {@link DocEntry} does
|
|
21
|
+
* not carry position information.
|
|
22
|
+
*
|
|
23
|
+
* @param entries The entries to deduplicate.
|
|
24
|
+
* @returns A new array with duplicates removed, preserving insertion order.
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
function deduplicateDocEntries(entries) {
|
|
28
|
+
const seen = /* @__PURE__ */ new Set();
|
|
29
|
+
const result = [];
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
if (entry.term.type === "argument") {
|
|
32
|
+
result.push(entry);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const key = getDocEntryKey(entry);
|
|
36
|
+
if (!seen.has(key)) {
|
|
37
|
+
seen.add(key);
|
|
38
|
+
result.push(entry);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Removes duplicate entries from a list of {@link DocFragment} values.
|
|
45
|
+
* Entry-type fragments are deduplicated by their surface syntax key.
|
|
46
|
+
* Section-type fragments have their entries deduplicated internally.
|
|
47
|
+
*
|
|
48
|
+
* @param fragments The fragments to deduplicate.
|
|
49
|
+
* @returns A new array with duplicate entries removed.
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
*/
|
|
52
|
+
function deduplicateDocFragments(fragments) {
|
|
53
|
+
const untitledSeen = /* @__PURE__ */ new Set();
|
|
54
|
+
const titledSectionMap = /* @__PURE__ */ new Map();
|
|
55
|
+
const slots = [];
|
|
56
|
+
for (const fragment of fragments) if (fragment.type === "entry") if (fragment.term.type === "argument") slots.push(fragment);
|
|
57
|
+
else {
|
|
58
|
+
const key = getDocEntryKey(fragment);
|
|
59
|
+
if (!untitledSeen.has(key)) {
|
|
60
|
+
untitledSeen.add(key);
|
|
61
|
+
slots.push(fragment);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (fragment.title == null) {
|
|
65
|
+
const dedupedEntries = [];
|
|
66
|
+
for (const entry of fragment.entries) {
|
|
67
|
+
if (entry.term.type === "argument") {
|
|
68
|
+
dedupedEntries.push(entry);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const key = getDocEntryKey(entry);
|
|
72
|
+
if (!untitledSeen.has(key)) {
|
|
73
|
+
untitledSeen.add(key);
|
|
74
|
+
dedupedEntries.push(entry);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (dedupedEntries.length > 0) slots.push({
|
|
78
|
+
...fragment,
|
|
79
|
+
type: "section",
|
|
80
|
+
entries: dedupedEntries
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
if (!titledSectionMap.has(fragment.title)) {
|
|
84
|
+
titledSectionMap.set(fragment.title, []);
|
|
85
|
+
slots.push(fragment.title);
|
|
86
|
+
}
|
|
87
|
+
titledSectionMap.get(fragment.title).push(...fragment.entries);
|
|
88
|
+
}
|
|
89
|
+
const result = [];
|
|
90
|
+
for (const slot of slots) if (typeof slot === "string") {
|
|
91
|
+
const entries = deduplicateDocEntries(titledSectionMap.get(slot));
|
|
92
|
+
if (entries.length > 0) result.push({
|
|
93
|
+
type: "section",
|
|
94
|
+
title: slot,
|
|
95
|
+
entries
|
|
96
|
+
});
|
|
97
|
+
} else result.push(slot);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
|
|
102
|
+
* {@link cloneUsageTerm}, and `description`, `default`, and `choices`
|
|
103
|
+
* messages are cloned via {@link cloneMessage}.
|
|
104
|
+
*
|
|
105
|
+
* @param entry The documentation entry to clone.
|
|
106
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
*/
|
|
109
|
+
function cloneDocEntry(entry) {
|
|
110
|
+
return {
|
|
111
|
+
term: require_usage.cloneUsageTerm(entry.term),
|
|
112
|
+
...entry.description != null && { description: require_message.cloneMessage(entry.description) },
|
|
113
|
+
...entry.default != null && { default: require_message.cloneMessage(entry.default) },
|
|
114
|
+
...entry.choices != null && { choices: require_message.cloneMessage(entry.choices) }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
5
117
|
/**
|
|
6
118
|
* Classifies a {@link DocSection} by its content type for use in the
|
|
7
119
|
* default smart sort.
|
|
@@ -327,4 +439,7 @@ function lastLineVisibleLength(text$1) {
|
|
|
327
439
|
}
|
|
328
440
|
|
|
329
441
|
//#endregion
|
|
442
|
+
exports.cloneDocEntry = cloneDocEntry;
|
|
443
|
+
exports.deduplicateDocEntries = deduplicateDocEntries;
|
|
444
|
+
exports.deduplicateDocFragments = deduplicateDocFragments;
|
|
330
445
|
exports.formatDocPage = formatDocPage;
|
package/dist/doc.d.cts
CHANGED
|
@@ -103,6 +103,40 @@ interface DocFragments {
|
|
|
103
103
|
*/
|
|
104
104
|
readonly footer?: Message;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Removes duplicate {@link DocEntry} values that share the same surface
|
|
108
|
+
* syntax (same term type and identifying names). When duplicates exist,
|
|
109
|
+
* the first occurrence is kept and later ones are discarded.
|
|
110
|
+
*
|
|
111
|
+
* Positional argument entries are never deduplicated because they are
|
|
112
|
+
* distinguished by position, not by metavar, and {@link DocEntry} does
|
|
113
|
+
* not carry position information.
|
|
114
|
+
*
|
|
115
|
+
* @param entries The entries to deduplicate.
|
|
116
|
+
* @returns A new array with duplicates removed, preserving insertion order.
|
|
117
|
+
* @since 1.0.0
|
|
118
|
+
*/
|
|
119
|
+
declare function deduplicateDocEntries(entries: readonly DocEntry[]): DocEntry[];
|
|
120
|
+
/**
|
|
121
|
+
* Removes duplicate entries from a list of {@link DocFragment} values.
|
|
122
|
+
* Entry-type fragments are deduplicated by their surface syntax key.
|
|
123
|
+
* Section-type fragments have their entries deduplicated internally.
|
|
124
|
+
*
|
|
125
|
+
* @param fragments The fragments to deduplicate.
|
|
126
|
+
* @returns A new array with duplicate entries removed.
|
|
127
|
+
* @since 1.0.0
|
|
128
|
+
*/
|
|
129
|
+
declare function deduplicateDocFragments(fragments: readonly DocFragment[]): DocFragment[];
|
|
130
|
+
/**
|
|
131
|
+
* Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
|
|
132
|
+
* {@link cloneUsageTerm}, and `description`, `default`, and `choices`
|
|
133
|
+
* messages are cloned via {@link cloneMessage}.
|
|
134
|
+
*
|
|
135
|
+
* @param entry The documentation entry to clone.
|
|
136
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
137
|
+
* @since 1.0.0
|
|
138
|
+
*/
|
|
139
|
+
declare function cloneDocEntry(entry: DocEntry): DocEntry;
|
|
106
140
|
/**
|
|
107
141
|
* Configuration for customizing default value display formatting.
|
|
108
142
|
*
|
|
@@ -291,4 +325,4 @@ interface DocPageFormatOptions {
|
|
|
291
325
|
*/
|
|
292
326
|
declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
|
|
293
327
|
//#endregion
|
|
294
|
-
export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage };
|
|
328
|
+
export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage };
|
package/dist/doc.d.ts
CHANGED
|
@@ -103,6 +103,40 @@ interface DocFragments {
|
|
|
103
103
|
*/
|
|
104
104
|
readonly footer?: Message;
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Removes duplicate {@link DocEntry} values that share the same surface
|
|
108
|
+
* syntax (same term type and identifying names). When duplicates exist,
|
|
109
|
+
* the first occurrence is kept and later ones are discarded.
|
|
110
|
+
*
|
|
111
|
+
* Positional argument entries are never deduplicated because they are
|
|
112
|
+
* distinguished by position, not by metavar, and {@link DocEntry} does
|
|
113
|
+
* not carry position information.
|
|
114
|
+
*
|
|
115
|
+
* @param entries The entries to deduplicate.
|
|
116
|
+
* @returns A new array with duplicates removed, preserving insertion order.
|
|
117
|
+
* @since 1.0.0
|
|
118
|
+
*/
|
|
119
|
+
declare function deduplicateDocEntries(entries: readonly DocEntry[]): DocEntry[];
|
|
120
|
+
/**
|
|
121
|
+
* Removes duplicate entries from a list of {@link DocFragment} values.
|
|
122
|
+
* Entry-type fragments are deduplicated by their surface syntax key.
|
|
123
|
+
* Section-type fragments have their entries deduplicated internally.
|
|
124
|
+
*
|
|
125
|
+
* @param fragments The fragments to deduplicate.
|
|
126
|
+
* @returns A new array with duplicate entries removed.
|
|
127
|
+
* @since 1.0.0
|
|
128
|
+
*/
|
|
129
|
+
declare function deduplicateDocFragments(fragments: readonly DocFragment[]): DocFragment[];
|
|
130
|
+
/**
|
|
131
|
+
* Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
|
|
132
|
+
* {@link cloneUsageTerm}, and `description`, `default`, and `choices`
|
|
133
|
+
* messages are cloned via {@link cloneMessage}.
|
|
134
|
+
*
|
|
135
|
+
* @param entry The documentation entry to clone.
|
|
136
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
137
|
+
* @since 1.0.0
|
|
138
|
+
*/
|
|
139
|
+
declare function cloneDocEntry(entry: DocEntry): DocEntry;
|
|
106
140
|
/**
|
|
107
141
|
* Configuration for customizing default value display formatting.
|
|
108
142
|
*
|
|
@@ -291,4 +325,4 @@ interface DocPageFormatOptions {
|
|
|
291
325
|
*/
|
|
292
326
|
declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
|
|
293
327
|
//#endregion
|
|
294
|
-
export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage };
|
|
328
|
+
export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage };
|
package/dist/doc.js
CHANGED
|
@@ -1,7 +1,119 @@
|
|
|
1
|
-
import { formatMessage, text } from "./message.js";
|
|
2
|
-
import { formatUsage, formatUsageTerm } from "./usage.js";
|
|
1
|
+
import { cloneMessage, formatMessage, text } from "./message.js";
|
|
2
|
+
import { cloneUsageTerm, formatUsage, formatUsageTerm } from "./usage.js";
|
|
3
3
|
|
|
4
4
|
//#region src/doc.ts
|
|
5
|
+
function getDocEntryKey(entry) {
|
|
6
|
+
const term = entry.term;
|
|
7
|
+
switch (term.type) {
|
|
8
|
+
case "command": return `command:${term.name}`;
|
|
9
|
+
case "option": return `option:${[...term.names].sort().join(",")}:${term.metavar ?? ""}`;
|
|
10
|
+
case "argument": return `argument:${term.metavar}`;
|
|
11
|
+
default: return JSON.stringify(term);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Removes duplicate {@link DocEntry} values that share the same surface
|
|
16
|
+
* syntax (same term type and identifying names). When duplicates exist,
|
|
17
|
+
* the first occurrence is kept and later ones are discarded.
|
|
18
|
+
*
|
|
19
|
+
* Positional argument entries are never deduplicated because they are
|
|
20
|
+
* distinguished by position, not by metavar, and {@link DocEntry} does
|
|
21
|
+
* not carry position information.
|
|
22
|
+
*
|
|
23
|
+
* @param entries The entries to deduplicate.
|
|
24
|
+
* @returns A new array with duplicates removed, preserving insertion order.
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
function deduplicateDocEntries(entries) {
|
|
28
|
+
const seen = /* @__PURE__ */ new Set();
|
|
29
|
+
const result = [];
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
if (entry.term.type === "argument") {
|
|
32
|
+
result.push(entry);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const key = getDocEntryKey(entry);
|
|
36
|
+
if (!seen.has(key)) {
|
|
37
|
+
seen.add(key);
|
|
38
|
+
result.push(entry);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Removes duplicate entries from a list of {@link DocFragment} values.
|
|
45
|
+
* Entry-type fragments are deduplicated by their surface syntax key.
|
|
46
|
+
* Section-type fragments have their entries deduplicated internally.
|
|
47
|
+
*
|
|
48
|
+
* @param fragments The fragments to deduplicate.
|
|
49
|
+
* @returns A new array with duplicate entries removed.
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
*/
|
|
52
|
+
function deduplicateDocFragments(fragments) {
|
|
53
|
+
const untitledSeen = /* @__PURE__ */ new Set();
|
|
54
|
+
const titledSectionMap = /* @__PURE__ */ new Map();
|
|
55
|
+
const slots = [];
|
|
56
|
+
for (const fragment of fragments) if (fragment.type === "entry") if (fragment.term.type === "argument") slots.push(fragment);
|
|
57
|
+
else {
|
|
58
|
+
const key = getDocEntryKey(fragment);
|
|
59
|
+
if (!untitledSeen.has(key)) {
|
|
60
|
+
untitledSeen.add(key);
|
|
61
|
+
slots.push(fragment);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (fragment.title == null) {
|
|
65
|
+
const dedupedEntries = [];
|
|
66
|
+
for (const entry of fragment.entries) {
|
|
67
|
+
if (entry.term.type === "argument") {
|
|
68
|
+
dedupedEntries.push(entry);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const key = getDocEntryKey(entry);
|
|
72
|
+
if (!untitledSeen.has(key)) {
|
|
73
|
+
untitledSeen.add(key);
|
|
74
|
+
dedupedEntries.push(entry);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (dedupedEntries.length > 0) slots.push({
|
|
78
|
+
...fragment,
|
|
79
|
+
type: "section",
|
|
80
|
+
entries: dedupedEntries
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
if (!titledSectionMap.has(fragment.title)) {
|
|
84
|
+
titledSectionMap.set(fragment.title, []);
|
|
85
|
+
slots.push(fragment.title);
|
|
86
|
+
}
|
|
87
|
+
titledSectionMap.get(fragment.title).push(...fragment.entries);
|
|
88
|
+
}
|
|
89
|
+
const result = [];
|
|
90
|
+
for (const slot of slots) if (typeof slot === "string") {
|
|
91
|
+
const entries = deduplicateDocEntries(titledSectionMap.get(slot));
|
|
92
|
+
if (entries.length > 0) result.push({
|
|
93
|
+
type: "section",
|
|
94
|
+
title: slot,
|
|
95
|
+
entries
|
|
96
|
+
});
|
|
97
|
+
} else result.push(slot);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a deep clone of a {@link DocEntry}. The `term` is cloned via
|
|
102
|
+
* {@link cloneUsageTerm}, and `description`, `default`, and `choices`
|
|
103
|
+
* messages are cloned via {@link cloneMessage}.
|
|
104
|
+
*
|
|
105
|
+
* @param entry The documentation entry to clone.
|
|
106
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
*/
|
|
109
|
+
function cloneDocEntry(entry) {
|
|
110
|
+
return {
|
|
111
|
+
term: cloneUsageTerm(entry.term),
|
|
112
|
+
...entry.description != null && { description: cloneMessage(entry.description) },
|
|
113
|
+
...entry.default != null && { default: cloneMessage(entry.default) },
|
|
114
|
+
...entry.choices != null && { choices: cloneMessage(entry.choices) }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
5
117
|
/**
|
|
6
118
|
* Classifies a {@link DocSection} by its content type for use in the
|
|
7
119
|
* default smart sort.
|
|
@@ -327,4 +439,4 @@ function lastLineVisibleLength(text$1) {
|
|
|
327
439
|
}
|
|
328
440
|
|
|
329
441
|
//#endregion
|
|
330
|
-
export { formatDocPage };
|
|
442
|
+
export { cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage };
|
package/dist/facade.cjs
CHANGED
|
@@ -3,9 +3,9 @@ const require_message = require('./message.cjs');
|
|
|
3
3
|
const require_completion = require('./completion.cjs');
|
|
4
4
|
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
5
5
|
const require_usage = require('./usage.cjs');
|
|
6
|
+
const require_doc = require('./doc.cjs');
|
|
6
7
|
const require_constructs = require('./constructs.cjs');
|
|
7
8
|
const require_context = require('./context.cjs');
|
|
8
|
-
const require_doc = require('./doc.cjs');
|
|
9
9
|
const require_modifiers = require('./modifiers.cjs');
|
|
10
10
|
const require_valueparser = require('./valueparser.cjs');
|
|
11
11
|
const require_primitives = require('./primitives.cjs');
|
package/dist/facade.js
CHANGED
|
@@ -3,9 +3,9 @@ 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 { formatUsage } from "./usage.js";
|
|
6
|
+
import { formatDocPage } from "./doc.js";
|
|
6
7
|
import { group, longestMatch, object } from "./constructs.js";
|
|
7
8
|
import { isPlaceholderValue } from "./context.js";
|
|
8
|
-
import { formatDocPage } from "./doc.js";
|
|
9
9
|
import { multiple, optional, withDefault } from "./modifiers.js";
|
|
10
10
|
import { string } from "./valueparser.js";
|
|
11
11
|
import { argument, command, constant, flag, option } from "./primitives.js";
|
package/dist/index.cjs
CHANGED
|
@@ -3,8 +3,8 @@ const require_message = require('./message.cjs');
|
|
|
3
3
|
const require_completion = require('./completion.cjs');
|
|
4
4
|
const require_dependency = require('./dependency.cjs');
|
|
5
5
|
const require_usage = require('./usage.cjs');
|
|
6
|
-
const require_constructs = require('./constructs.cjs');
|
|
7
6
|
const require_doc = require('./doc.cjs');
|
|
7
|
+
const require_constructs = require('./constructs.cjs');
|
|
8
8
|
const require_modifiers = require('./modifiers.cjs');
|
|
9
9
|
const require_nonempty = require('./nonempty.cjs');
|
|
10
10
|
const require_valueparser = require('./valueparser.cjs');
|
|
@@ -23,6 +23,9 @@ exports.checkBooleanOption = require_valueparser.checkBooleanOption;
|
|
|
23
23
|
exports.checkEnumOption = require_valueparser.checkEnumOption;
|
|
24
24
|
exports.choice = require_valueparser.choice;
|
|
25
25
|
exports.cidr = require_valueparser.cidr;
|
|
26
|
+
exports.cloneDocEntry = require_doc.cloneDocEntry;
|
|
27
|
+
exports.cloneUsage = require_usage.cloneUsage;
|
|
28
|
+
exports.cloneUsageTerm = require_usage.cloneUsageTerm;
|
|
26
29
|
exports.command = require_primitives.command;
|
|
27
30
|
exports.commandLine = require_message.commandLine;
|
|
28
31
|
exports.concat = require_constructs.concat;
|
|
@@ -31,6 +34,8 @@ exports.constant = require_primitives.constant;
|
|
|
31
34
|
exports.createDeferredParseState = require_dependency.createDeferredParseState;
|
|
32
35
|
exports.createDependencySourceState = require_dependency.createDependencySourceState;
|
|
33
36
|
exports.createPendingDependencySourceState = require_dependency.createPendingDependencySourceState;
|
|
37
|
+
exports.deduplicateDocEntries = require_doc.deduplicateDocEntries;
|
|
38
|
+
exports.deduplicateDocFragments = require_doc.deduplicateDocFragments;
|
|
34
39
|
exports.defaultValues = require_dependency.defaultValues;
|
|
35
40
|
exports.deferredParseMarker = require_dependency.deferredParseMarker;
|
|
36
41
|
exports.dependency = require_dependency.dependency;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
|
|
5
|
-
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
|
|
4
|
+
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
|
|
5
|
+
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage } from "./doc.cjs";
|
|
6
6
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, 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";
|
|
8
8
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.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, 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, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, 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, 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, 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, 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, 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,8 +1,8 @@
|
|
|
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, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
5
|
-
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.js";
|
|
4
|
+
import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
5
|
+
import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage } from "./doc.js";
|
|
6
6
|
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, 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";
|
|
8
8
|
import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.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, 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, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, 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, 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, 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, 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, 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,9 +2,9 @@ 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 { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
5
|
+
import { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
|
|
6
|
+
import { cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage } from "./doc.js";
|
|
6
7
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
7
|
-
import { formatDocPage } from "./doc.js";
|
|
8
8
|
import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
9
9
|
import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
10
10
|
import { checkBooleanOption, checkEnumOption, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.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, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, 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, 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, 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, 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/message.cjs
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/message.ts
|
|
3
3
|
/**
|
|
4
|
+
* Creates a deep clone of a {@link MessageTerm}. Most variants contain only
|
|
5
|
+
* primitive fields and are cloned via object spread. The `url` variant
|
|
6
|
+
* receives a new `URL` object (since `structuredClone` cannot handle `URL`
|
|
7
|
+
* on Node.js), and array-valued fields (`optionNames`, `values`) are
|
|
8
|
+
* shallow-copied.
|
|
9
|
+
*
|
|
10
|
+
* @param term The message term to clone.
|
|
11
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
function cloneMessageTerm(term) {
|
|
15
|
+
switch (term.type) {
|
|
16
|
+
case "optionNames": return {
|
|
17
|
+
...term,
|
|
18
|
+
optionNames: [...term.optionNames]
|
|
19
|
+
};
|
|
20
|
+
case "values": return {
|
|
21
|
+
...term,
|
|
22
|
+
values: [...term.values]
|
|
23
|
+
};
|
|
24
|
+
case "url": return {
|
|
25
|
+
type: "url",
|
|
26
|
+
url: new URL(term.url.href)
|
|
27
|
+
};
|
|
28
|
+
default: return { ...term };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a deep clone of a {@link Message} array and all of its terms.
|
|
33
|
+
*
|
|
34
|
+
* @param msg The message to clone.
|
|
35
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
36
|
+
* @since 1.0.0
|
|
37
|
+
*/
|
|
38
|
+
function cloneMessage(msg) {
|
|
39
|
+
return msg.map(cloneMessageTerm);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
4
42
|
* Creates a structured message with template strings and values.
|
|
5
43
|
*
|
|
6
44
|
* This function allows creating messages where specific values can be
|
|
@@ -386,6 +424,8 @@ function formatMessage(msg, options = {}) {
|
|
|
386
424
|
}
|
|
387
425
|
|
|
388
426
|
//#endregion
|
|
427
|
+
exports.cloneMessage = cloneMessage;
|
|
428
|
+
exports.cloneMessageTerm = cloneMessageTerm;
|
|
389
429
|
exports.commandLine = commandLine;
|
|
390
430
|
exports.envVar = envVar;
|
|
391
431
|
exports.formatMessage = formatMessage;
|
package/dist/message.d.cts
CHANGED
|
@@ -151,6 +151,26 @@ type MessageTerm =
|
|
|
151
151
|
* displayed to the user with specific formatting.
|
|
152
152
|
*/
|
|
153
153
|
type Message = readonly MessageTerm[];
|
|
154
|
+
/**
|
|
155
|
+
* Creates a deep clone of a {@link MessageTerm}. Most variants contain only
|
|
156
|
+
* primitive fields and are cloned via object spread. The `url` variant
|
|
157
|
+
* receives a new `URL` object (since `structuredClone` cannot handle `URL`
|
|
158
|
+
* on Node.js), and array-valued fields (`optionNames`, `values`) are
|
|
159
|
+
* shallow-copied.
|
|
160
|
+
*
|
|
161
|
+
* @param term The message term to clone.
|
|
162
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
163
|
+
* @since 1.0.0
|
|
164
|
+
*/
|
|
165
|
+
declare function cloneMessageTerm(term: MessageTerm): MessageTerm;
|
|
166
|
+
/**
|
|
167
|
+
* Creates a deep clone of a {@link Message} array and all of its terms.
|
|
168
|
+
*
|
|
169
|
+
* @param msg The message to clone.
|
|
170
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
171
|
+
* @since 1.0.0
|
|
172
|
+
*/
|
|
173
|
+
declare function cloneMessage(msg: Message): Message;
|
|
154
174
|
/**
|
|
155
175
|
* Creates a structured message with template strings and values.
|
|
156
176
|
*
|
|
@@ -380,4 +400,4 @@ interface MessageFormatOptions {
|
|
|
380
400
|
*/
|
|
381
401
|
declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
|
|
382
402
|
//#endregion
|
|
383
|
-
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
|
403
|
+
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, cloneMessage, cloneMessageTerm, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/message.d.ts
CHANGED
|
@@ -151,6 +151,26 @@ type MessageTerm =
|
|
|
151
151
|
* displayed to the user with specific formatting.
|
|
152
152
|
*/
|
|
153
153
|
type Message = readonly MessageTerm[];
|
|
154
|
+
/**
|
|
155
|
+
* Creates a deep clone of a {@link MessageTerm}. Most variants contain only
|
|
156
|
+
* primitive fields and are cloned via object spread. The `url` variant
|
|
157
|
+
* receives a new `URL` object (since `structuredClone` cannot handle `URL`
|
|
158
|
+
* on Node.js), and array-valued fields (`optionNames`, `values`) are
|
|
159
|
+
* shallow-copied.
|
|
160
|
+
*
|
|
161
|
+
* @param term The message term to clone.
|
|
162
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
163
|
+
* @since 1.0.0
|
|
164
|
+
*/
|
|
165
|
+
declare function cloneMessageTerm(term: MessageTerm): MessageTerm;
|
|
166
|
+
/**
|
|
167
|
+
* Creates a deep clone of a {@link Message} array and all of its terms.
|
|
168
|
+
*
|
|
169
|
+
* @param msg The message to clone.
|
|
170
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
171
|
+
* @since 1.0.0
|
|
172
|
+
*/
|
|
173
|
+
declare function cloneMessage(msg: Message): Message;
|
|
154
174
|
/**
|
|
155
175
|
* Creates a structured message with template strings and values.
|
|
156
176
|
*
|
|
@@ -380,4 +400,4 @@ interface MessageFormatOptions {
|
|
|
380
400
|
*/
|
|
381
401
|
declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
|
|
382
402
|
//#endregion
|
|
383
|
-
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
|
403
|
+
export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, cloneMessage, cloneMessageTerm, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/message.js
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
//#region src/message.ts
|
|
2
2
|
/**
|
|
3
|
+
* Creates a deep clone of a {@link MessageTerm}. Most variants contain only
|
|
4
|
+
* primitive fields and are cloned via object spread. The `url` variant
|
|
5
|
+
* receives a new `URL` object (since `structuredClone` cannot handle `URL`
|
|
6
|
+
* on Node.js), and array-valued fields (`optionNames`, `values`) are
|
|
7
|
+
* shallow-copied.
|
|
8
|
+
*
|
|
9
|
+
* @param term The message term to clone.
|
|
10
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
function cloneMessageTerm(term) {
|
|
14
|
+
switch (term.type) {
|
|
15
|
+
case "optionNames": return {
|
|
16
|
+
...term,
|
|
17
|
+
optionNames: [...term.optionNames]
|
|
18
|
+
};
|
|
19
|
+
case "values": return {
|
|
20
|
+
...term,
|
|
21
|
+
values: [...term.values]
|
|
22
|
+
};
|
|
23
|
+
case "url": return {
|
|
24
|
+
type: "url",
|
|
25
|
+
url: new URL(term.url.href)
|
|
26
|
+
};
|
|
27
|
+
default: return { ...term };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a deep clone of a {@link Message} array and all of its terms.
|
|
32
|
+
*
|
|
33
|
+
* @param msg The message to clone.
|
|
34
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
*/
|
|
37
|
+
function cloneMessage(msg) {
|
|
38
|
+
return msg.map(cloneMessageTerm);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
3
41
|
* Creates a structured message with template strings and values.
|
|
4
42
|
*
|
|
5
43
|
* This function allows creating messages where specific values can be
|
|
@@ -385,4 +423,4 @@ function formatMessage(msg, options = {}) {
|
|
|
385
423
|
}
|
|
386
424
|
|
|
387
425
|
//#endregion
|
|
388
|
-
export { commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
|
426
|
+
export { cloneMessage, cloneMessageTerm, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, url, value, valueSet, values };
|
package/dist/parser.cjs
CHANGED
|
@@ -2,6 +2,7 @@ const require_annotations = require('./annotations.cjs');
|
|
|
2
2
|
const require_message = require('./message.cjs');
|
|
3
3
|
const require_mode_dispatch = require('./mode-dispatch.cjs');
|
|
4
4
|
const require_usage = require('./usage.cjs');
|
|
5
|
+
const require_doc = require('./doc.cjs');
|
|
5
6
|
const require_constructs = require('./constructs.cjs');
|
|
6
7
|
const require_modifiers = require('./modifiers.cjs');
|
|
7
8
|
const require_primitives = require('./primitives.cjs');
|
|
@@ -388,13 +389,13 @@ function buildDocPage(parser, context, args) {
|
|
|
388
389
|
untitledSection = { entries: [] };
|
|
389
390
|
buildingSections.push(untitledSection);
|
|
390
391
|
}
|
|
391
|
-
untitledSection.entries.push(fragment);
|
|
392
|
+
untitledSection.entries.push(require_doc.cloneDocEntry(fragment));
|
|
392
393
|
} else if (fragment.type === "section") if (fragment.title == null) {
|
|
393
394
|
if (untitledSection == null) {
|
|
394
395
|
untitledSection = { entries: [] };
|
|
395
396
|
buildingSections.push(untitledSection);
|
|
396
397
|
}
|
|
397
|
-
untitledSection.entries.push(...fragment.entries);
|
|
398
|
+
untitledSection.entries.push(...fragment.entries.map(require_doc.cloneDocEntry));
|
|
398
399
|
} else {
|
|
399
400
|
let section = titledSectionMap.get(fragment.title);
|
|
400
401
|
if (section == null) {
|
|
@@ -405,15 +406,15 @@ function buildDocPage(parser, context, args) {
|
|
|
405
406
|
titledSectionMap.set(fragment.title, section);
|
|
406
407
|
buildingSections.push(section);
|
|
407
408
|
}
|
|
408
|
-
section.entries.push(...fragment.entries);
|
|
409
|
+
section.entries.push(...fragment.entries.map(require_doc.cloneDocEntry));
|
|
409
410
|
}
|
|
410
411
|
const sections = buildingSections;
|
|
411
|
-
const usage =
|
|
412
|
+
const usage = require_usage.cloneUsage(require_usage.normalizeUsage(parser.usage));
|
|
412
413
|
const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
|
|
413
414
|
if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
|
|
414
|
-
const defaultUsageLine = usage.slice(usageIndex + 1);
|
|
415
|
+
const defaultUsageLine = require_usage.cloneUsage(usage.slice(usageIndex + 1));
|
|
415
416
|
const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
|
|
416
|
-
const normalizedCustomUsageLine = require_usage.normalizeUsage(customUsageLine);
|
|
417
|
+
const normalizedCustomUsageLine = require_usage.cloneUsage(require_usage.normalizeUsage(customUsageLine));
|
|
417
418
|
usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
|
|
418
419
|
};
|
|
419
420
|
let i = 0;
|
|
@@ -434,17 +435,18 @@ function buildDocPage(parser, context, args) {
|
|
|
434
435
|
if (effectiveArgs.length === 0 && usage.length > 0) {
|
|
435
436
|
const first = usage[0];
|
|
436
437
|
if (first.type === "command" && first.usageLine != null) {
|
|
437
|
-
const defaultUsageLine = usage.slice(1);
|
|
438
|
+
const defaultUsageLine = require_usage.cloneUsage(usage.slice(1));
|
|
438
439
|
const customUsageLine = typeof first.usageLine === "function" ? first.usageLine(defaultUsageLine) : first.usageLine;
|
|
439
|
-
|
|
440
|
+
const normalizedCustomUsageLine = require_usage.cloneUsage(require_usage.normalizeUsage(customUsageLine));
|
|
441
|
+
usage.splice(1, usage.length - 1, ...normalizedCustomUsageLine);
|
|
440
442
|
}
|
|
441
443
|
}
|
|
442
444
|
return {
|
|
443
445
|
usage,
|
|
444
446
|
sections,
|
|
445
|
-
...brief != null && { brief },
|
|
446
|
-
...description != null && { description },
|
|
447
|
-
...footer != null && { footer }
|
|
447
|
+
...brief != null && { brief: require_message.cloneMessage(brief) },
|
|
448
|
+
...description != null && { description: require_message.cloneMessage(description) },
|
|
449
|
+
...footer != null && { footer: require_message.cloneMessage(footer) }
|
|
448
450
|
};
|
|
449
451
|
}
|
|
450
452
|
|
package/dist/parser.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./annotations.js";
|
|
2
|
-
import { message } from "./message.js";
|
|
2
|
+
import { cloneMessage, message } from "./message.js";
|
|
3
3
|
import { dispatchByMode } from "./mode-dispatch.js";
|
|
4
|
-
import { normalizeUsage } from "./usage.js";
|
|
4
|
+
import { cloneUsage, normalizeUsage } from "./usage.js";
|
|
5
|
+
import { cloneDocEntry } from "./doc.js";
|
|
5
6
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
|
|
6
7
|
import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
7
8
|
import { argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
|
|
@@ -388,13 +389,13 @@ function buildDocPage(parser, context, args) {
|
|
|
388
389
|
untitledSection = { entries: [] };
|
|
389
390
|
buildingSections.push(untitledSection);
|
|
390
391
|
}
|
|
391
|
-
untitledSection.entries.push(fragment);
|
|
392
|
+
untitledSection.entries.push(cloneDocEntry(fragment));
|
|
392
393
|
} else if (fragment.type === "section") if (fragment.title == null) {
|
|
393
394
|
if (untitledSection == null) {
|
|
394
395
|
untitledSection = { entries: [] };
|
|
395
396
|
buildingSections.push(untitledSection);
|
|
396
397
|
}
|
|
397
|
-
untitledSection.entries.push(...fragment.entries);
|
|
398
|
+
untitledSection.entries.push(...fragment.entries.map(cloneDocEntry));
|
|
398
399
|
} else {
|
|
399
400
|
let section = titledSectionMap.get(fragment.title);
|
|
400
401
|
if (section == null) {
|
|
@@ -405,15 +406,15 @@ function buildDocPage(parser, context, args) {
|
|
|
405
406
|
titledSectionMap.set(fragment.title, section);
|
|
406
407
|
buildingSections.push(section);
|
|
407
408
|
}
|
|
408
|
-
section.entries.push(...fragment.entries);
|
|
409
|
+
section.entries.push(...fragment.entries.map(cloneDocEntry));
|
|
409
410
|
}
|
|
410
411
|
const sections = buildingSections;
|
|
411
|
-
const usage =
|
|
412
|
+
const usage = cloneUsage(normalizeUsage(parser.usage));
|
|
412
413
|
const maybeApplyCommandUsageLine = (term, arg, isLastArg, usageIndex) => {
|
|
413
414
|
if (term?.type !== "command" || term.name !== arg || !isLastArg || term.usageLine == null) return;
|
|
414
|
-
const defaultUsageLine = usage.slice(usageIndex + 1);
|
|
415
|
+
const defaultUsageLine = cloneUsage(usage.slice(usageIndex + 1));
|
|
415
416
|
const customUsageLine = typeof term.usageLine === "function" ? term.usageLine(defaultUsageLine) : term.usageLine;
|
|
416
|
-
const normalizedCustomUsageLine = normalizeUsage(customUsageLine);
|
|
417
|
+
const normalizedCustomUsageLine = cloneUsage(normalizeUsage(customUsageLine));
|
|
417
418
|
usage.splice(usageIndex + 1, usage.length - (usageIndex + 1), ...normalizedCustomUsageLine);
|
|
418
419
|
};
|
|
419
420
|
let i = 0;
|
|
@@ -434,17 +435,18 @@ function buildDocPage(parser, context, args) {
|
|
|
434
435
|
if (effectiveArgs.length === 0 && usage.length > 0) {
|
|
435
436
|
const first = usage[0];
|
|
436
437
|
if (first.type === "command" && first.usageLine != null) {
|
|
437
|
-
const defaultUsageLine = usage.slice(1);
|
|
438
|
+
const defaultUsageLine = cloneUsage(usage.slice(1));
|
|
438
439
|
const customUsageLine = typeof first.usageLine === "function" ? first.usageLine(defaultUsageLine) : first.usageLine;
|
|
439
|
-
|
|
440
|
+
const normalizedCustomUsageLine = cloneUsage(normalizeUsage(customUsageLine));
|
|
441
|
+
usage.splice(1, usage.length - 1, ...normalizedCustomUsageLine);
|
|
440
442
|
}
|
|
441
443
|
}
|
|
442
444
|
return {
|
|
443
445
|
usage,
|
|
444
446
|
sections,
|
|
445
|
-
...brief != null && { brief },
|
|
446
|
-
...description != null && { description },
|
|
447
|
-
...footer != null && { footer }
|
|
447
|
+
...brief != null && { brief: cloneMessage(brief) },
|
|
448
|
+
...description != null && { description: cloneMessage(description) },
|
|
449
|
+
...footer != null && { footer: cloneMessage(footer) }
|
|
448
450
|
};
|
|
449
451
|
}
|
|
450
452
|
|
package/dist/usage.cjs
CHANGED
|
@@ -237,6 +237,59 @@ function normalizeUsageTerm(term) {
|
|
|
237
237
|
};
|
|
238
238
|
} else return term;
|
|
239
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Creates a deep clone of a single {@link UsageTerm}. Recursive term
|
|
242
|
+
* variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
|
|
243
|
+
* For `command` terms, a function-valued `usageLine` is preserved by
|
|
244
|
+
* reference (functions are stateless callbacks), while an array-valued
|
|
245
|
+
* `usageLine` is deep-cloned.
|
|
246
|
+
*
|
|
247
|
+
* @param term The usage term to clone.
|
|
248
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
249
|
+
* @since 1.0.0
|
|
250
|
+
*/
|
|
251
|
+
function cloneUsageTerm(term) {
|
|
252
|
+
switch (term.type) {
|
|
253
|
+
case "argument": return { ...term };
|
|
254
|
+
case "option": return {
|
|
255
|
+
...term,
|
|
256
|
+
names: [...term.names]
|
|
257
|
+
};
|
|
258
|
+
case "command": {
|
|
259
|
+
if (term.usageLine == null || typeof term.usageLine === "function") return { ...term };
|
|
260
|
+
return {
|
|
261
|
+
...term,
|
|
262
|
+
usageLine: term.usageLine.map(cloneUsageTerm)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
case "optional": return {
|
|
266
|
+
type: "optional",
|
|
267
|
+
terms: term.terms.map(cloneUsageTerm)
|
|
268
|
+
};
|
|
269
|
+
case "multiple": return {
|
|
270
|
+
type: "multiple",
|
|
271
|
+
terms: term.terms.map(cloneUsageTerm),
|
|
272
|
+
min: term.min
|
|
273
|
+
};
|
|
274
|
+
case "exclusive": return {
|
|
275
|
+
type: "exclusive",
|
|
276
|
+
terms: term.terms.map((u) => u.map(cloneUsageTerm))
|
|
277
|
+
};
|
|
278
|
+
case "literal":
|
|
279
|
+
case "passthrough":
|
|
280
|
+
case "ellipsis": return { ...term };
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Creates a deep clone of a {@link Usage} array and all of its terms.
|
|
285
|
+
*
|
|
286
|
+
* @param usage The usage array to clone.
|
|
287
|
+
* @returns A mutable array of deeply cloned usage terms.
|
|
288
|
+
* @since 1.0.0
|
|
289
|
+
*/
|
|
290
|
+
function cloneUsage(usage) {
|
|
291
|
+
return usage.map(cloneUsageTerm);
|
|
292
|
+
}
|
|
240
293
|
function filterUsageForDisplay(usage, isHidden = isUsageHidden) {
|
|
241
294
|
const terms = [];
|
|
242
295
|
for (const term of usage) {
|
|
@@ -433,6 +486,8 @@ function* formatUsageTermInternal(term, options) {
|
|
|
433
486
|
}
|
|
434
487
|
|
|
435
488
|
//#endregion
|
|
489
|
+
exports.cloneUsage = cloneUsage;
|
|
490
|
+
exports.cloneUsageTerm = cloneUsageTerm;
|
|
436
491
|
exports.extractArgumentMetavars = extractArgumentMetavars;
|
|
437
492
|
exports.extractCommandNames = extractCommandNames;
|
|
438
493
|
exports.extractOptionNames = extractOptionNames;
|
package/dist/usage.d.cts
CHANGED
|
@@ -347,6 +347,26 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
|
|
|
347
347
|
* and terms sorted for optimal readability.
|
|
348
348
|
*/
|
|
349
349
|
declare function normalizeUsage(usage: Usage): Usage;
|
|
350
|
+
/**
|
|
351
|
+
* Creates a deep clone of a single {@link UsageTerm}. Recursive term
|
|
352
|
+
* variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
|
|
353
|
+
* For `command` terms, a function-valued `usageLine` is preserved by
|
|
354
|
+
* reference (functions are stateless callbacks), while an array-valued
|
|
355
|
+
* `usageLine` is deep-cloned.
|
|
356
|
+
*
|
|
357
|
+
* @param term The usage term to clone.
|
|
358
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
359
|
+
* @since 1.0.0
|
|
360
|
+
*/
|
|
361
|
+
declare function cloneUsageTerm(term: UsageTerm): UsageTerm;
|
|
362
|
+
/**
|
|
363
|
+
* Creates a deep clone of a {@link Usage} array and all of its terms.
|
|
364
|
+
*
|
|
365
|
+
* @param usage The usage array to clone.
|
|
366
|
+
* @returns A mutable array of deeply cloned usage terms.
|
|
367
|
+
* @since 1.0.0
|
|
368
|
+
*/
|
|
369
|
+
declare function cloneUsage(usage: Usage): UsageTerm[];
|
|
350
370
|
/**
|
|
351
371
|
* Options for formatting a single {@link UsageTerm}.
|
|
352
372
|
*/
|
|
@@ -378,4 +398,4 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
|
|
|
378
398
|
*/
|
|
379
399
|
declare function formatUsageTerm(term: UsageTerm, options?: UsageTermFormatOptions): string;
|
|
380
400
|
//#endregion
|
|
381
|
-
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
|
401
|
+
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
package/dist/usage.d.ts
CHANGED
|
@@ -347,6 +347,26 @@ declare function formatUsage(programName: string, usage: Usage, options?: UsageF
|
|
|
347
347
|
* and terms sorted for optimal readability.
|
|
348
348
|
*/
|
|
349
349
|
declare function normalizeUsage(usage: Usage): Usage;
|
|
350
|
+
/**
|
|
351
|
+
* Creates a deep clone of a single {@link UsageTerm}. Recursive term
|
|
352
|
+
* variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
|
|
353
|
+
* For `command` terms, a function-valued `usageLine` is preserved by
|
|
354
|
+
* reference (functions are stateless callbacks), while an array-valued
|
|
355
|
+
* `usageLine` is deep-cloned.
|
|
356
|
+
*
|
|
357
|
+
* @param term The usage term to clone.
|
|
358
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
359
|
+
* @since 1.0.0
|
|
360
|
+
*/
|
|
361
|
+
declare function cloneUsageTerm(term: UsageTerm): UsageTerm;
|
|
362
|
+
/**
|
|
363
|
+
* Creates a deep clone of a {@link Usage} array and all of its terms.
|
|
364
|
+
*
|
|
365
|
+
* @param usage The usage array to clone.
|
|
366
|
+
* @returns A mutable array of deeply cloned usage terms.
|
|
367
|
+
* @since 1.0.0
|
|
368
|
+
*/
|
|
369
|
+
declare function cloneUsage(usage: Usage): UsageTerm[];
|
|
350
370
|
/**
|
|
351
371
|
* Options for formatting a single {@link UsageTerm}.
|
|
352
372
|
*/
|
|
@@ -378,4 +398,4 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
|
|
|
378
398
|
*/
|
|
379
399
|
declare function formatUsageTerm(term: UsageTerm, options?: UsageTermFormatOptions): string;
|
|
380
400
|
//#endregion
|
|
381
|
-
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
|
401
|
+
export { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
package/dist/usage.js
CHANGED
|
@@ -236,6 +236,59 @@ function normalizeUsageTerm(term) {
|
|
|
236
236
|
};
|
|
237
237
|
} else return term;
|
|
238
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Creates a deep clone of a single {@link UsageTerm}. Recursive term
|
|
241
|
+
* variants (`optional`, `multiple`, `exclusive`) are cloned recursively.
|
|
242
|
+
* For `command` terms, a function-valued `usageLine` is preserved by
|
|
243
|
+
* reference (functions are stateless callbacks), while an array-valued
|
|
244
|
+
* `usageLine` is deep-cloned.
|
|
245
|
+
*
|
|
246
|
+
* @param term The usage term to clone.
|
|
247
|
+
* @returns A structurally equal but referentially distinct copy.
|
|
248
|
+
* @since 1.0.0
|
|
249
|
+
*/
|
|
250
|
+
function cloneUsageTerm(term) {
|
|
251
|
+
switch (term.type) {
|
|
252
|
+
case "argument": return { ...term };
|
|
253
|
+
case "option": return {
|
|
254
|
+
...term,
|
|
255
|
+
names: [...term.names]
|
|
256
|
+
};
|
|
257
|
+
case "command": {
|
|
258
|
+
if (term.usageLine == null || typeof term.usageLine === "function") return { ...term };
|
|
259
|
+
return {
|
|
260
|
+
...term,
|
|
261
|
+
usageLine: term.usageLine.map(cloneUsageTerm)
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
case "optional": return {
|
|
265
|
+
type: "optional",
|
|
266
|
+
terms: term.terms.map(cloneUsageTerm)
|
|
267
|
+
};
|
|
268
|
+
case "multiple": return {
|
|
269
|
+
type: "multiple",
|
|
270
|
+
terms: term.terms.map(cloneUsageTerm),
|
|
271
|
+
min: term.min
|
|
272
|
+
};
|
|
273
|
+
case "exclusive": return {
|
|
274
|
+
type: "exclusive",
|
|
275
|
+
terms: term.terms.map((u) => u.map(cloneUsageTerm))
|
|
276
|
+
};
|
|
277
|
+
case "literal":
|
|
278
|
+
case "passthrough":
|
|
279
|
+
case "ellipsis": return { ...term };
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Creates a deep clone of a {@link Usage} array and all of its terms.
|
|
284
|
+
*
|
|
285
|
+
* @param usage The usage array to clone.
|
|
286
|
+
* @returns A mutable array of deeply cloned usage terms.
|
|
287
|
+
* @since 1.0.0
|
|
288
|
+
*/
|
|
289
|
+
function cloneUsage(usage) {
|
|
290
|
+
return usage.map(cloneUsageTerm);
|
|
291
|
+
}
|
|
239
292
|
function filterUsageForDisplay(usage, isHidden = isUsageHidden) {
|
|
240
293
|
const terms = [];
|
|
241
294
|
for (const term of usage) {
|
|
@@ -432,4 +485,4 @@ function* formatUsageTermInternal(term, options) {
|
|
|
432
485
|
}
|
|
433
486
|
|
|
434
487
|
//#endregion
|
|
435
|
-
export { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|
|
488
|
+
export { cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage };
|