@optique/core 1.0.0-dev.1288 → 1.0.0-dev.1291
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/doc.cjs +12 -0
- package/dist/doc.js +12 -0
- package/dist/usage.cjs +12 -8
- package/dist/usage.d.cts +10 -0
- package/dist/usage.d.ts +10 -0
- package/dist/usage.js +12 -8
- package/package.json +1 -1
package/dist/doc.cjs
CHANGED
|
@@ -76,6 +76,17 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
76
76
|
const termIndent = options.termIndent ?? 2;
|
|
77
77
|
const termWidth = options.termWidth ?? 26;
|
|
78
78
|
if (options.maxWidth != null && (!Number.isFinite(options.maxWidth) || !Number.isInteger(options.maxWidth))) throw new TypeError(`maxWidth must be a finite integer, got ${options.maxWidth}.`);
|
|
79
|
+
const filteredSections = page.sections.map((s) => ({
|
|
80
|
+
...s,
|
|
81
|
+
entries: s.entries.filter((e) => {
|
|
82
|
+
const rendered = require_usage.formatUsageTerm(e.term, { context: "doc" });
|
|
83
|
+
return rendered.trim() !== "";
|
|
84
|
+
})
|
|
85
|
+
}));
|
|
86
|
+
page = {
|
|
87
|
+
...page,
|
|
88
|
+
sections: filteredSections
|
|
89
|
+
};
|
|
79
90
|
if (options.maxWidth != null) {
|
|
80
91
|
const hasEntries = page.sections.some((s) => s.entries.length > 0);
|
|
81
92
|
const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
|
|
@@ -171,6 +182,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
171
182
|
const term = require_usage.formatUsageTerm(entry.term, {
|
|
172
183
|
colors: options.colors,
|
|
173
184
|
optionsSeparator: ", ",
|
|
185
|
+
context: "doc",
|
|
174
186
|
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
|
|
175
187
|
});
|
|
176
188
|
const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - effectiveTermWidth - 2;
|
package/dist/doc.js
CHANGED
|
@@ -76,6 +76,17 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
76
76
|
const termIndent = options.termIndent ?? 2;
|
|
77
77
|
const termWidth = options.termWidth ?? 26;
|
|
78
78
|
if (options.maxWidth != null && (!Number.isFinite(options.maxWidth) || !Number.isInteger(options.maxWidth))) throw new TypeError(`maxWidth must be a finite integer, got ${options.maxWidth}.`);
|
|
79
|
+
const filteredSections = page.sections.map((s) => ({
|
|
80
|
+
...s,
|
|
81
|
+
entries: s.entries.filter((e) => {
|
|
82
|
+
const rendered = formatUsageTerm(e.term, { context: "doc" });
|
|
83
|
+
return rendered.trim() !== "";
|
|
84
|
+
})
|
|
85
|
+
}));
|
|
86
|
+
page = {
|
|
87
|
+
...page,
|
|
88
|
+
sections: filteredSections
|
|
89
|
+
};
|
|
79
90
|
if (options.maxWidth != null) {
|
|
80
91
|
const hasEntries = page.sections.some((s) => s.entries.length > 0);
|
|
81
92
|
const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
|
|
@@ -171,6 +182,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
171
182
|
const term = formatUsageTerm(entry.term, {
|
|
172
183
|
colors: options.colors,
|
|
173
184
|
optionsSeparator: ", ",
|
|
185
|
+
context: "doc",
|
|
174
186
|
maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
|
|
175
187
|
});
|
|
176
188
|
const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - effectiveTermWidth - 2;
|
package/dist/usage.cjs
CHANGED
|
@@ -237,12 +237,16 @@ function normalizeUsageTerm(term) {
|
|
|
237
237
|
};
|
|
238
238
|
} else return term;
|
|
239
239
|
}
|
|
240
|
-
function filterUsageForDisplay(usage) {
|
|
240
|
+
function filterUsageForDisplay(usage, isHidden = isUsageHidden) {
|
|
241
241
|
const terms = [];
|
|
242
242
|
for (const term of usage) {
|
|
243
|
-
if ((term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") &&
|
|
243
|
+
if ((term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") && isHidden(term.hidden)) continue;
|
|
244
|
+
if (term.type === "option" && term.names.length === 0) continue;
|
|
245
|
+
if (term.type === "command" && term.name === "") continue;
|
|
246
|
+
if (term.type === "argument" && term.metavar.length === 0) continue;
|
|
247
|
+
if (term.type === "literal" && term.value === "") continue;
|
|
244
248
|
if (term.type === "optional") {
|
|
245
|
-
const filtered = filterUsageForDisplay(term.terms);
|
|
249
|
+
const filtered = filterUsageForDisplay(term.terms, isHidden);
|
|
246
250
|
if (filtered.length > 0) terms.push({
|
|
247
251
|
type: "optional",
|
|
248
252
|
terms: filtered
|
|
@@ -250,7 +254,7 @@ function filterUsageForDisplay(usage) {
|
|
|
250
254
|
continue;
|
|
251
255
|
}
|
|
252
256
|
if (term.type === "multiple") {
|
|
253
|
-
const filtered = filterUsageForDisplay(term.terms);
|
|
257
|
+
const filtered = filterUsageForDisplay(term.terms, isHidden);
|
|
254
258
|
if (filtered.length > 0) terms.push({
|
|
255
259
|
type: "multiple",
|
|
256
260
|
terms: filtered,
|
|
@@ -261,8 +265,8 @@ function filterUsageForDisplay(usage) {
|
|
|
261
265
|
if (term.type === "exclusive") {
|
|
262
266
|
const filteredBranches = term.terms.map((branch) => {
|
|
263
267
|
const first = branch[0];
|
|
264
|
-
if (first?.type === "command" &&
|
|
265
|
-
return filterUsageForDisplay(branch);
|
|
268
|
+
if (first?.type === "command" && isHidden(first.hidden)) return [];
|
|
269
|
+
return filterUsageForDisplay(branch, isHidden);
|
|
266
270
|
}).filter((branch) => branch.length > 0);
|
|
267
271
|
if (filteredBranches.length > 0) terms.push({
|
|
268
272
|
type: "exclusive",
|
|
@@ -277,7 +281,6 @@ function filterUsageForDisplay(usage) {
|
|
|
277
281
|
function* formatUsageTerms(terms, options) {
|
|
278
282
|
let i = 0;
|
|
279
283
|
for (const t of terms) {
|
|
280
|
-
if ("hidden" in t && (t.type === "argument" || t.type === "option" || t.type === "command" || t.type === "passthrough") && isUsageHidden(t.hidden)) continue;
|
|
281
284
|
if (i > 0) yield {
|
|
282
285
|
text: " ",
|
|
283
286
|
width: 1
|
|
@@ -296,7 +299,8 @@ function* formatUsageTerms(terms, options) {
|
|
|
296
299
|
* @returns A formatted string representation of the usage term.
|
|
297
300
|
*/
|
|
298
301
|
function formatUsageTerm(term, options = {}) {
|
|
299
|
-
const
|
|
302
|
+
const hiddenCheck = options.context === "doc" ? isDocHidden : isUsageHidden;
|
|
303
|
+
const visibleTerms = filterUsageForDisplay([term], hiddenCheck);
|
|
300
304
|
if (visibleTerms.length < 1) return "";
|
|
301
305
|
let lineWidth = 0;
|
|
302
306
|
let output = "";
|
package/dist/usage.d.cts
CHANGED
|
@@ -356,6 +356,16 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
|
|
|
356
356
|
* @default `"/"`
|
|
357
357
|
*/
|
|
358
358
|
readonly optionsSeparator?: string;
|
|
359
|
+
/**
|
|
360
|
+
* The rendering context, which determines which hidden visibility values
|
|
361
|
+
* cause terms to be filtered out.
|
|
362
|
+
*
|
|
363
|
+
* - `"usage"` (default): filters terms hidden from usage output
|
|
364
|
+
* - `"doc"`: filters terms hidden from documentation output
|
|
365
|
+
* @default `"usage"`
|
|
366
|
+
* @since 1.0.0
|
|
367
|
+
*/
|
|
368
|
+
readonly context?: "usage" | "doc";
|
|
359
369
|
}
|
|
360
370
|
/**
|
|
361
371
|
* Formats a single {@link UsageTerm} into a string representation
|
package/dist/usage.d.ts
CHANGED
|
@@ -356,6 +356,16 @@ interface UsageTermFormatOptions extends UsageFormatOptions {
|
|
|
356
356
|
* @default `"/"`
|
|
357
357
|
*/
|
|
358
358
|
readonly optionsSeparator?: string;
|
|
359
|
+
/**
|
|
360
|
+
* The rendering context, which determines which hidden visibility values
|
|
361
|
+
* cause terms to be filtered out.
|
|
362
|
+
*
|
|
363
|
+
* - `"usage"` (default): filters terms hidden from usage output
|
|
364
|
+
* - `"doc"`: filters terms hidden from documentation output
|
|
365
|
+
* @default `"usage"`
|
|
366
|
+
* @since 1.0.0
|
|
367
|
+
*/
|
|
368
|
+
readonly context?: "usage" | "doc";
|
|
359
369
|
}
|
|
360
370
|
/**
|
|
361
371
|
* Formats a single {@link UsageTerm} into a string representation
|
package/dist/usage.js
CHANGED
|
@@ -236,12 +236,16 @@ function normalizeUsageTerm(term) {
|
|
|
236
236
|
};
|
|
237
237
|
} else return term;
|
|
238
238
|
}
|
|
239
|
-
function filterUsageForDisplay(usage) {
|
|
239
|
+
function filterUsageForDisplay(usage, isHidden = isUsageHidden) {
|
|
240
240
|
const terms = [];
|
|
241
241
|
for (const term of usage) {
|
|
242
|
-
if ((term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") &&
|
|
242
|
+
if ((term.type === "argument" || term.type === "option" || term.type === "command" || term.type === "passthrough") && isHidden(term.hidden)) continue;
|
|
243
|
+
if (term.type === "option" && term.names.length === 0) continue;
|
|
244
|
+
if (term.type === "command" && term.name === "") continue;
|
|
245
|
+
if (term.type === "argument" && term.metavar.length === 0) continue;
|
|
246
|
+
if (term.type === "literal" && term.value === "") continue;
|
|
243
247
|
if (term.type === "optional") {
|
|
244
|
-
const filtered = filterUsageForDisplay(term.terms);
|
|
248
|
+
const filtered = filterUsageForDisplay(term.terms, isHidden);
|
|
245
249
|
if (filtered.length > 0) terms.push({
|
|
246
250
|
type: "optional",
|
|
247
251
|
terms: filtered
|
|
@@ -249,7 +253,7 @@ function filterUsageForDisplay(usage) {
|
|
|
249
253
|
continue;
|
|
250
254
|
}
|
|
251
255
|
if (term.type === "multiple") {
|
|
252
|
-
const filtered = filterUsageForDisplay(term.terms);
|
|
256
|
+
const filtered = filterUsageForDisplay(term.terms, isHidden);
|
|
253
257
|
if (filtered.length > 0) terms.push({
|
|
254
258
|
type: "multiple",
|
|
255
259
|
terms: filtered,
|
|
@@ -260,8 +264,8 @@ function filterUsageForDisplay(usage) {
|
|
|
260
264
|
if (term.type === "exclusive") {
|
|
261
265
|
const filteredBranches = term.terms.map((branch) => {
|
|
262
266
|
const first = branch[0];
|
|
263
|
-
if (first?.type === "command" &&
|
|
264
|
-
return filterUsageForDisplay(branch);
|
|
267
|
+
if (first?.type === "command" && isHidden(first.hidden)) return [];
|
|
268
|
+
return filterUsageForDisplay(branch, isHidden);
|
|
265
269
|
}).filter((branch) => branch.length > 0);
|
|
266
270
|
if (filteredBranches.length > 0) terms.push({
|
|
267
271
|
type: "exclusive",
|
|
@@ -276,7 +280,6 @@ function filterUsageForDisplay(usage) {
|
|
|
276
280
|
function* formatUsageTerms(terms, options) {
|
|
277
281
|
let i = 0;
|
|
278
282
|
for (const t of terms) {
|
|
279
|
-
if ("hidden" in t && (t.type === "argument" || t.type === "option" || t.type === "command" || t.type === "passthrough") && isUsageHidden(t.hidden)) continue;
|
|
280
283
|
if (i > 0) yield {
|
|
281
284
|
text: " ",
|
|
282
285
|
width: 1
|
|
@@ -295,7 +298,8 @@ function* formatUsageTerms(terms, options) {
|
|
|
295
298
|
* @returns A formatted string representation of the usage term.
|
|
296
299
|
*/
|
|
297
300
|
function formatUsageTerm(term, options = {}) {
|
|
298
|
-
const
|
|
301
|
+
const hiddenCheck = options.context === "doc" ? isDocHidden : isUsageHidden;
|
|
302
|
+
const visibleTerms = filterUsageForDisplay([term], hiddenCheck);
|
|
299
303
|
if (visibleTerms.length < 1) return "";
|
|
300
304
|
let lineWidth = 0;
|
|
301
305
|
let output = "";
|