@optique/core 1.0.0-dev.1279 → 1.0.0-dev.1290
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/facade.cjs +20 -0
- package/dist/facade.js +20 -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/facade.cjs
CHANGED
|
@@ -879,24 +879,44 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
879
879
|
const helpOptionArgs = helpTerminatorIndex >= 0 ? args.slice(0, helpTerminatorIndex) : args;
|
|
880
880
|
const hasHelpOption = helpOptionConfig ? completionCommandConfig && completionCommandNames.includes(args[0]) ? args.length >= 2 && helpOptionNames.includes(args[1]) : helpOptionNames.some((n) => helpOptionArgs.includes(n)) : false;
|
|
881
881
|
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], false, sectionOrder);
|
|
882
|
+
const hasMetaEntryBefore = (endIndex) => {
|
|
883
|
+
const argsBefore = args.slice(0, endIndex);
|
|
884
|
+
if (helpOptionConfig && helpOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
885
|
+
if (versionOptionConfig && versionOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
886
|
+
if (endIndex > 0) {
|
|
887
|
+
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
888
|
+
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
889
|
+
}
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
let completionOptionIndex = -1;
|
|
882
893
|
if (completionOptionConfig) {
|
|
883
894
|
const loopBound = helpTerminatorIndex >= 0 ? helpTerminatorIndex : args.length;
|
|
884
895
|
for (let i = 0; i < loopBound; i++) {
|
|
885
896
|
const arg = args[i];
|
|
886
897
|
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
887
898
|
if (equalsMatch) {
|
|
899
|
+
if (hasMetaEntryBefore(i)) {
|
|
900
|
+
completionOptionIndex = i;
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
888
903
|
const shell = arg.slice(equalsMatch.length + 1);
|
|
889
904
|
const completionArgs = args.slice(i + 1);
|
|
890
905
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
891
906
|
}
|
|
892
907
|
const exactMatch = completionOptionNames.includes(arg);
|
|
893
908
|
if (exactMatch) {
|
|
909
|
+
if (hasMetaEntryBefore(i)) {
|
|
910
|
+
completionOptionIndex = i;
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
894
913
|
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
895
914
|
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
896
915
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
897
916
|
}
|
|
898
917
|
}
|
|
899
918
|
}
|
|
919
|
+
if (completionOptionIndex >= 0) args = args.slice(0, completionOptionIndex);
|
|
900
920
|
}
|
|
901
921
|
const augmentedParser = !options.help && !options.version && !options.completion ? parser : combineWithHelpVersion(parser, helpParsers, versionParsers, completionParsers, {
|
|
902
922
|
helpCommandGroup: helpCommandConfig?.group,
|
package/dist/facade.js
CHANGED
|
@@ -879,24 +879,44 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
879
879
|
const helpOptionArgs = helpTerminatorIndex >= 0 ? args.slice(0, helpTerminatorIndex) : args;
|
|
880
880
|
const hasHelpOption = helpOptionConfig ? completionCommandConfig && completionCommandNames.includes(args[0]) ? args.length >= 2 && helpOptionNames.includes(args[1]) : helpOptionNames.some((n) => helpOptionArgs.includes(n)) : false;
|
|
881
881
|
if (completionCommandConfig && args.length >= 1 && completionCommandNames.includes(args[0]) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], false, sectionOrder);
|
|
882
|
+
const hasMetaEntryBefore = (endIndex) => {
|
|
883
|
+
const argsBefore = args.slice(0, endIndex);
|
|
884
|
+
if (helpOptionConfig && helpOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
885
|
+
if (versionOptionConfig && versionOptionNames.some((n) => argsBefore.includes(n))) return true;
|
|
886
|
+
if (endIndex > 0) {
|
|
887
|
+
if (helpCommandConfig && helpCommandNames.includes(args[0])) return true;
|
|
888
|
+
if (versionCommandConfig && versionCommandNames.includes(args[0])) return true;
|
|
889
|
+
}
|
|
890
|
+
return false;
|
|
891
|
+
};
|
|
892
|
+
let completionOptionIndex = -1;
|
|
882
893
|
if (completionOptionConfig) {
|
|
883
894
|
const loopBound = helpTerminatorIndex >= 0 ? helpTerminatorIndex : args.length;
|
|
884
895
|
for (let i = 0; i < loopBound; i++) {
|
|
885
896
|
const arg = args[i];
|
|
886
897
|
const equalsMatch = completionOptionNames.find((n) => arg.startsWith(n + "="));
|
|
887
898
|
if (equalsMatch) {
|
|
899
|
+
if (hasMetaEntryBefore(i)) {
|
|
900
|
+
completionOptionIndex = i;
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
888
903
|
const shell = arg.slice(equalsMatch.length + 1);
|
|
889
904
|
const completionArgs = args.slice(i + 1);
|
|
890
905
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
891
906
|
}
|
|
892
907
|
const exactMatch = completionOptionNames.includes(arg);
|
|
893
908
|
if (exactMatch) {
|
|
909
|
+
if (hasMetaEntryBefore(i)) {
|
|
910
|
+
completionOptionIndex = i;
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
894
913
|
const shell = i + 1 < args.length ? args[i + 1] : "";
|
|
895
914
|
const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
|
|
896
915
|
return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], true, sectionOrder);
|
|
897
916
|
}
|
|
898
917
|
}
|
|
899
918
|
}
|
|
919
|
+
if (completionOptionIndex >= 0) args = args.slice(0, completionOptionIndex);
|
|
900
920
|
}
|
|
901
921
|
const augmentedParser = !options.help && !options.version && !options.completion ? parser : combineWithHelpVersion(parser, helpParsers, versionParsers, completionParsers, {
|
|
902
922
|
helpCommandGroup: helpCommandConfig?.group,
|
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 = "";
|