@optique/core 1.4.0-dev.2733 → 1.4.0-dev.2737
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 +19 -9
- package/dist/constructs.js +19 -9
- package/dist/doc.cjs +2 -2
- package/dist/doc.d.cts +10 -2
- package/dist/doc.d.ts +10 -2
- package/dist/doc.js +2 -2
- package/dist/execution-context.cjs +3 -2
- package/dist/execution-context.js +3 -2
- package/dist/facade.cjs +13 -9
- package/dist/facade.d.cts +4 -3
- package/dist/facade.d.ts +4 -3
- package/dist/facade.js +13 -9
- package/dist/internal/command-doc-policy.cjs +168 -0
- package/dist/internal/command-doc-policy.d.cts +77 -0
- package/dist/internal/command-doc-policy.d.ts +77 -0
- package/dist/internal/command-doc-policy.js +160 -0
- package/dist/internal/parser.cjs +8 -4
- package/dist/internal/parser.js +8 -4
- package/dist/primitives.cjs +20 -3
- package/dist/primitives.d.cts +10 -1
- package/dist/primitives.d.ts +10 -1
- package/dist/primitives.js +20 -3
- package/package.json +10 -2
- package/skills/optique/SKILL.md +3 -3
package/dist/constructs.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_internal_annotations = require('./internal/annotations.cjs');
|
|
2
|
+
const require_internal_command_doc_policy = require('./internal/command-doc-policy.cjs');
|
|
2
3
|
const require_validate = require('./validate.cjs');
|
|
3
4
|
const require_usage = require('./usage.cjs');
|
|
4
5
|
const require_message = require('./message.cjs');
|
|
@@ -1187,7 +1188,8 @@ function isUnselectedBooleanOptionState(state) {
|
|
|
1187
1188
|
return state != null && typeof state === "object" && "success" in state && state.success === true && "value" in state && state.value === false;
|
|
1188
1189
|
}
|
|
1189
1190
|
function preserveExclusiveStateAfterOptionsTerminator(context, result) {
|
|
1190
|
-
const
|
|
1191
|
+
const childExec = require_execution_context.mergeChildExec(context.exec, result.next.exec);
|
|
1192
|
+
const mergedExec = childExec == null ? childExec : require_internal_command_doc_policy.mergeCommandDocPolicy(context.exec, context.exec, childExec);
|
|
1191
1193
|
return {
|
|
1192
1194
|
success: true,
|
|
1193
1195
|
next: {
|
|
@@ -1528,7 +1530,7 @@ function or(...args) {
|
|
|
1528
1530
|
let optionsTerminatorResult = null;
|
|
1529
1531
|
let provisionalAmbiguous = false;
|
|
1530
1532
|
for (const { parser, index: i, state: childState } of orderedParsers) {
|
|
1531
|
-
const childContext = withChildContext$1(require_short_option.forkOptionScope(context), i, childState, parser);
|
|
1533
|
+
const childContext = withChildContext$1(require_short_option.forkOptionScope(commandDocBranchContext(context, activeState?.[0], i)), i, childState, parser);
|
|
1532
1534
|
const result = parser.parse(childContext);
|
|
1533
1535
|
if (result.success && result.consumed.length === 0) {
|
|
1534
1536
|
const own = require_passthrough.retainConsumingFailureHint(void 0, childContext, result.next);
|
|
@@ -1583,7 +1585,7 @@ function or(...args) {
|
|
|
1583
1585
|
}
|
|
1584
1586
|
const previouslyConsumed = activeState[1].consumed;
|
|
1585
1587
|
const checkResult = parser.parse({
|
|
1586
|
-
...withChildContext$1(context, i, parser.initialState, parser),
|
|
1588
|
+
...withChildContext$1(commandDocBranchContext(context, activeState?.[0], i), i, parser.initialState, parser),
|
|
1587
1589
|
buffer: previouslyConsumed
|
|
1588
1590
|
});
|
|
1589
1591
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1686,7 +1688,7 @@ function or(...args) {
|
|
|
1686
1688
|
if (activeState != null && activeState[1].success) {
|
|
1687
1689
|
const previouslyConsumed = activeState[1].consumed;
|
|
1688
1690
|
const checkResult = provisionalConsuming.parser.parse({
|
|
1689
|
-
...withChildContext$1(require_short_option.forkOptionScope(context), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1691
|
+
...withChildContext$1(require_short_option.forkOptionScope(commandDocBranchContext(context, activeState?.[0], provisionalConsuming.index)), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1690
1692
|
buffer: previouslyConsumed
|
|
1691
1693
|
});
|
|
1692
1694
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1737,7 +1739,7 @@ function or(...args) {
|
|
|
1737
1739
|
let optionsTerminatorResult = null;
|
|
1738
1740
|
let provisionalAmbiguous = false;
|
|
1739
1741
|
for (const { parser, index: i, state: childState } of orderedParsers) {
|
|
1740
|
-
const childContext = withChildContext$1(require_short_option.forkOptionScope(context), i, childState, parser);
|
|
1742
|
+
const childContext = withChildContext$1(require_short_option.forkOptionScope(commandDocBranchContext(context, activeState?.[0], i)), i, childState, parser);
|
|
1741
1743
|
const resultOrPromise = parser.parse(childContext);
|
|
1742
1744
|
const result = await resultOrPromise;
|
|
1743
1745
|
if (result.success && result.consumed.length === 0) {
|
|
@@ -1793,7 +1795,7 @@ function or(...args) {
|
|
|
1793
1795
|
}
|
|
1794
1796
|
const previouslyConsumed = activeState[1].consumed;
|
|
1795
1797
|
const checkResultOrPromise = parser.parse({
|
|
1796
|
-
...withChildContext$1(context, i, parser.initialState, parser),
|
|
1798
|
+
...withChildContext$1(commandDocBranchContext(context, activeState?.[0], i), i, parser.initialState, parser),
|
|
1797
1799
|
buffer: previouslyConsumed
|
|
1798
1800
|
});
|
|
1799
1801
|
const checkResult = await checkResultOrPromise;
|
|
@@ -1898,7 +1900,7 @@ function or(...args) {
|
|
|
1898
1900
|
if (activeState != null && activeState[1].success) {
|
|
1899
1901
|
const previouslyConsumed = activeState[1].consumed;
|
|
1900
1902
|
const checkResult = await provisionalConsuming.parser.parse({
|
|
1901
|
-
...withChildContext$1(require_short_option.forkOptionScope(context), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1903
|
+
...withChildContext$1(require_short_option.forkOptionScope(commandDocBranchContext(context, activeState?.[0], provisionalConsuming.index)), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1902
1904
|
buffer: previouslyConsumed
|
|
1903
1905
|
});
|
|
1904
1906
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -2114,7 +2116,7 @@ function createLongestMatch(...args) {
|
|
|
2114
2116
|
let error = getInitialError(context);
|
|
2115
2117
|
let consumingFailure;
|
|
2116
2118
|
for (const { parser, index: i, state: childState } of selectExclusiveChildren(syncParsers, context.state)) {
|
|
2117
|
-
const childContext = withChildContext$1(require_short_option.forkOptionScope(context), i, childState, parser);
|
|
2119
|
+
const childContext = withChildContext$1(require_short_option.forkOptionScope(commandDocBranchContext(context, normalizeExclusiveState(context.state)?.[0], i)), i, childState, parser);
|
|
2118
2120
|
const result = parser.parse(childContext);
|
|
2119
2121
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
2120
2122
|
optionsTerminatorMatches.push({
|
|
@@ -2152,7 +2154,7 @@ function createLongestMatch(...args) {
|
|
|
2152
2154
|
let error = getInitialError(context);
|
|
2153
2155
|
let consumingFailure;
|
|
2154
2156
|
for (const { parser, index: i, state: childState } of selectExclusiveChildren(parsers, context.state)) {
|
|
2155
|
-
const childContext = withChildContext$1(require_short_option.forkOptionScope(context), i, childState, parser);
|
|
2157
|
+
const childContext = withChildContext$1(require_short_option.forkOptionScope(commandDocBranchContext(context, normalizeExclusiveState(context.state)?.[0], i)), i, childState, parser);
|
|
2156
2158
|
const resultOrPromise = parser.parse(childContext);
|
|
2157
2159
|
const result = await resultOrPromise;
|
|
2158
2160
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
@@ -7953,6 +7955,14 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7953
7955
|
}
|
|
7954
7956
|
}));
|
|
7955
7957
|
}
|
|
7958
|
+
function commandDocBranchContext(context, activeIndex, nextIndex) {
|
|
7959
|
+
if (activeIndex == null || activeIndex === nextIndex) return context;
|
|
7960
|
+
const exec = require_internal_command_doc_policy.withoutCommandDocPolicySubtree(context.exec, [...context.exec?.path ?? [], activeIndex]);
|
|
7961
|
+
return exec === context.exec ? context : {
|
|
7962
|
+
...context,
|
|
7963
|
+
exec
|
|
7964
|
+
};
|
|
7965
|
+
}
|
|
7956
7966
|
|
|
7957
7967
|
//#endregion
|
|
7958
7968
|
exports.DuplicateOptionError = DuplicateOptionError;
|
package/dist/constructs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { annotateFreshArray, getAnnotations, inheritAnnotations } from "./internal/annotations.js";
|
|
2
|
+
import { mergeCommandDocPolicy, withoutCommandDocPolicySubtree } from "./internal/command-doc-policy.js";
|
|
2
3
|
import { validateLabel } from "./validate.js";
|
|
3
4
|
import { extractArgumentMetavars, extractCommandNames, extractOptionNames, isDocHidden, mergeHidden } from "./usage.js";
|
|
4
5
|
import { message, optionName, text, values } from "./message.js";
|
|
@@ -1187,7 +1188,8 @@ function isUnselectedBooleanOptionState(state) {
|
|
|
1187
1188
|
return state != null && typeof state === "object" && "success" in state && state.success === true && "value" in state && state.value === false;
|
|
1188
1189
|
}
|
|
1189
1190
|
function preserveExclusiveStateAfterOptionsTerminator(context, result) {
|
|
1190
|
-
const
|
|
1191
|
+
const childExec = mergeChildExec(context.exec, result.next.exec);
|
|
1192
|
+
const mergedExec = childExec == null ? childExec : mergeCommandDocPolicy(context.exec, context.exec, childExec);
|
|
1191
1193
|
return {
|
|
1192
1194
|
success: true,
|
|
1193
1195
|
next: {
|
|
@@ -1528,7 +1530,7 @@ function or(...args) {
|
|
|
1528
1530
|
let optionsTerminatorResult = null;
|
|
1529
1531
|
let provisionalAmbiguous = false;
|
|
1530
1532
|
for (const { parser, index: i, state: childState } of orderedParsers) {
|
|
1531
|
-
const childContext = withChildContext$1(forkOptionScope(context), i, childState, parser);
|
|
1533
|
+
const childContext = withChildContext$1(forkOptionScope(commandDocBranchContext(context, activeState?.[0], i)), i, childState, parser);
|
|
1532
1534
|
const result = parser.parse(childContext);
|
|
1533
1535
|
if (result.success && result.consumed.length === 0) {
|
|
1534
1536
|
const own = retainConsumingFailureHint(void 0, childContext, result.next);
|
|
@@ -1583,7 +1585,7 @@ function or(...args) {
|
|
|
1583
1585
|
}
|
|
1584
1586
|
const previouslyConsumed = activeState[1].consumed;
|
|
1585
1587
|
const checkResult = parser.parse({
|
|
1586
|
-
...withChildContext$1(context, i, parser.initialState, parser),
|
|
1588
|
+
...withChildContext$1(commandDocBranchContext(context, activeState?.[0], i), i, parser.initialState, parser),
|
|
1587
1589
|
buffer: previouslyConsumed
|
|
1588
1590
|
});
|
|
1589
1591
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1686,7 +1688,7 @@ function or(...args) {
|
|
|
1686
1688
|
if (activeState != null && activeState[1].success) {
|
|
1687
1689
|
const previouslyConsumed = activeState[1].consumed;
|
|
1688
1690
|
const checkResult = provisionalConsuming.parser.parse({
|
|
1689
|
-
...withChildContext$1(forkOptionScope(context), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1691
|
+
...withChildContext$1(forkOptionScope(commandDocBranchContext(context, activeState?.[0], provisionalConsuming.index)), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1690
1692
|
buffer: previouslyConsumed
|
|
1691
1693
|
});
|
|
1692
1694
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -1737,7 +1739,7 @@ function or(...args) {
|
|
|
1737
1739
|
let optionsTerminatorResult = null;
|
|
1738
1740
|
let provisionalAmbiguous = false;
|
|
1739
1741
|
for (const { parser, index: i, state: childState } of orderedParsers) {
|
|
1740
|
-
const childContext = withChildContext$1(forkOptionScope(context), i, childState, parser);
|
|
1742
|
+
const childContext = withChildContext$1(forkOptionScope(commandDocBranchContext(context, activeState?.[0], i)), i, childState, parser);
|
|
1741
1743
|
const resultOrPromise = parser.parse(childContext);
|
|
1742
1744
|
const result = await resultOrPromise;
|
|
1743
1745
|
if (result.success && result.consumed.length === 0) {
|
|
@@ -1793,7 +1795,7 @@ function or(...args) {
|
|
|
1793
1795
|
}
|
|
1794
1796
|
const previouslyConsumed = activeState[1].consumed;
|
|
1795
1797
|
const checkResultOrPromise = parser.parse({
|
|
1796
|
-
...withChildContext$1(context, i, parser.initialState, parser),
|
|
1798
|
+
...withChildContext$1(commandDocBranchContext(context, activeState?.[0], i), i, parser.initialState, parser),
|
|
1797
1799
|
buffer: previouslyConsumed
|
|
1798
1800
|
});
|
|
1799
1801
|
const checkResult = await checkResultOrPromise;
|
|
@@ -1898,7 +1900,7 @@ function or(...args) {
|
|
|
1898
1900
|
if (activeState != null && activeState[1].success) {
|
|
1899
1901
|
const previouslyConsumed = activeState[1].consumed;
|
|
1900
1902
|
const checkResult = await provisionalConsuming.parser.parse({
|
|
1901
|
-
...withChildContext$1(forkOptionScope(context), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1903
|
+
...withChildContext$1(forkOptionScope(commandDocBranchContext(context, activeState?.[0], provisionalConsuming.index)), provisionalConsuming.index, provisionalConsuming.parser.initialState, provisionalConsuming.parser),
|
|
1902
1904
|
buffer: previouslyConsumed
|
|
1903
1905
|
});
|
|
1904
1906
|
const canConsumeShared = checkResult.success && checkResult.consumed.length === previouslyConsumed.length && checkResult.consumed.every((c, idx) => c === previouslyConsumed[idx]);
|
|
@@ -2114,7 +2116,7 @@ function createLongestMatch(...args) {
|
|
|
2114
2116
|
let error = getInitialError(context);
|
|
2115
2117
|
let consumingFailure;
|
|
2116
2118
|
for (const { parser, index: i, state: childState } of selectExclusiveChildren(syncParsers, context.state)) {
|
|
2117
|
-
const childContext = withChildContext$1(forkOptionScope(context), i, childState, parser);
|
|
2119
|
+
const childContext = withChildContext$1(forkOptionScope(commandDocBranchContext(context, normalizeExclusiveState(context.state)?.[0], i)), i, childState, parser);
|
|
2118
2120
|
const result = parser.parse(childContext);
|
|
2119
2121
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
2120
2122
|
optionsTerminatorMatches.push({
|
|
@@ -2152,7 +2154,7 @@ function createLongestMatch(...args) {
|
|
|
2152
2154
|
let error = getInitialError(context);
|
|
2153
2155
|
let consumingFailure;
|
|
2154
2156
|
for (const { parser, index: i, state: childState } of selectExclusiveChildren(parsers, context.state)) {
|
|
2155
|
-
const childContext = withChildContext$1(forkOptionScope(context), i, childState, parser);
|
|
2157
|
+
const childContext = withChildContext$1(forkOptionScope(commandDocBranchContext(context, normalizeExclusiveState(context.state)?.[0], i)), i, childState, parser);
|
|
2156
2158
|
const resultOrPromise = parser.parse(childContext);
|
|
2157
2159
|
const result = await resultOrPromise;
|
|
2158
2160
|
if (isOptionsTerminatorOnlyResult(context, result)) {
|
|
@@ -7953,6 +7955,14 @@ function conditional(discriminator, branches, defaultBranch, options) {
|
|
|
7953
7955
|
}
|
|
7954
7956
|
}));
|
|
7955
7957
|
}
|
|
7958
|
+
function commandDocBranchContext(context, activeIndex, nextIndex) {
|
|
7959
|
+
if (activeIndex == null || activeIndex === nextIndex) return context;
|
|
7960
|
+
const exec = withoutCommandDocPolicySubtree(context.exec, [...context.exec?.path ?? [], activeIndex]);
|
|
7961
|
+
return exec === context.exec ? context : {
|
|
7962
|
+
...context,
|
|
7963
|
+
exec
|
|
7964
|
+
};
|
|
7965
|
+
}
|
|
7956
7966
|
|
|
7957
7967
|
//#endregion
|
|
7958
7968
|
export { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, seq, tuple };
|
package/dist/doc.cjs
CHANGED
|
@@ -350,13 +350,13 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
350
350
|
}
|
|
351
351
|
return rendered;
|
|
352
352
|
};
|
|
353
|
-
const
|
|
353
|
+
const showUsage = options.showUsage ?? page.showUsage ?? true;
|
|
354
|
+
const usageLabel = page.usage != null && showUsage ? require_text_layout.spaceAfterLabel(label("Usage:", "usage")) : "";
|
|
354
355
|
const usageLabelWidth = require_text_layout.measureText(usageLabel).lastLineWidth;
|
|
355
356
|
const defaultStyle = require_terminal_internal.styleCode(options.theme?.annotationStyles?.default ?? { dim: true });
|
|
356
357
|
const choicesStyle = require_terminal_internal.styleCode(options.theme?.annotationStyles?.choices ?? { dim: true });
|
|
357
358
|
require_validate.validateProgramName(programName);
|
|
358
359
|
const termIndent = options.termIndent ?? 2;
|
|
359
|
-
const showUsage = options.showUsage ?? true;
|
|
360
360
|
if (options.maxWidth != null && (!Number.isFinite(options.maxWidth) || !Number.isInteger(options.maxWidth))) throw new TypeError(`maxWidth must be a finite integer, got ${options.maxWidth}.`);
|
|
361
361
|
const filteredSections = page.sections.map((s) => ({
|
|
362
362
|
...s,
|
package/dist/doc.d.cts
CHANGED
|
@@ -77,6 +77,13 @@ interface EnvironmentBindingDoc {
|
|
|
77
77
|
* for commands, options, and other related information.
|
|
78
78
|
*/
|
|
79
79
|
interface DocPage {
|
|
80
|
+
/**
|
|
81
|
+
* Default visibility of the usage synopsis for this page.
|
|
82
|
+
* Explicit formatter options override this value; omission defaults to true.
|
|
83
|
+
* Runner-produced pages include the selected command or runner setting.
|
|
84
|
+
* @since 1.4.0
|
|
85
|
+
*/
|
|
86
|
+
readonly showUsage?: boolean;
|
|
80
87
|
/** Independent environment documentation in this page's scope. @since 1.4.0 */
|
|
81
88
|
readonly environmentBindings?: readonly EnvironmentBindingDoc[];
|
|
82
89
|
readonly brief?: Message;
|
|
@@ -339,9 +346,10 @@ interface DocPageFormatOptions {
|
|
|
339
346
|
*/
|
|
340
347
|
maxWidth?: number;
|
|
341
348
|
/**
|
|
342
|
-
* Whether to include the usage synopsis in the output.
|
|
349
|
+
* Whether to include the usage synopsis in the output. Overrides the
|
|
350
|
+
* page's `showUsage` default when supplied.
|
|
343
351
|
*
|
|
344
|
-
* @default `true`
|
|
352
|
+
* @default The page default, or `true` when it is omitted.
|
|
345
353
|
* @since 1.2.0
|
|
346
354
|
*/
|
|
347
355
|
showUsage?: boolean;
|
package/dist/doc.d.ts
CHANGED
|
@@ -77,6 +77,13 @@ interface EnvironmentBindingDoc {
|
|
|
77
77
|
* for commands, options, and other related information.
|
|
78
78
|
*/
|
|
79
79
|
interface DocPage {
|
|
80
|
+
/**
|
|
81
|
+
* Default visibility of the usage synopsis for this page.
|
|
82
|
+
* Explicit formatter options override this value; omission defaults to true.
|
|
83
|
+
* Runner-produced pages include the selected command or runner setting.
|
|
84
|
+
* @since 1.4.0
|
|
85
|
+
*/
|
|
86
|
+
readonly showUsage?: boolean;
|
|
80
87
|
/** Independent environment documentation in this page's scope. @since 1.4.0 */
|
|
81
88
|
readonly environmentBindings?: readonly EnvironmentBindingDoc[];
|
|
82
89
|
readonly brief?: Message;
|
|
@@ -339,9 +346,10 @@ interface DocPageFormatOptions {
|
|
|
339
346
|
*/
|
|
340
347
|
maxWidth?: number;
|
|
341
348
|
/**
|
|
342
|
-
* Whether to include the usage synopsis in the output.
|
|
349
|
+
* Whether to include the usage synopsis in the output. Overrides the
|
|
350
|
+
* page's `showUsage` default when supplied.
|
|
343
351
|
*
|
|
344
|
-
* @default `true`
|
|
352
|
+
* @default The page default, or `true` when it is omitted.
|
|
345
353
|
* @since 1.2.0
|
|
346
354
|
*/
|
|
347
355
|
showUsage?: boolean;
|
package/dist/doc.js
CHANGED
|
@@ -350,13 +350,13 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
350
350
|
}
|
|
351
351
|
return rendered;
|
|
352
352
|
};
|
|
353
|
-
const
|
|
353
|
+
const showUsage = options.showUsage ?? page.showUsage ?? true;
|
|
354
|
+
const usageLabel = page.usage != null && showUsage ? spaceAfterLabel(label("Usage:", "usage")) : "";
|
|
354
355
|
const usageLabelWidth = measureText(usageLabel).lastLineWidth;
|
|
355
356
|
const defaultStyle = styleCode(options.theme?.annotationStyles?.default ?? { dim: true });
|
|
356
357
|
const choicesStyle = styleCode(options.theme?.annotationStyles?.choices ?? { dim: true });
|
|
357
358
|
validateProgramName(programName);
|
|
358
359
|
const termIndent = options.termIndent ?? 2;
|
|
359
|
-
const showUsage = options.showUsage ?? true;
|
|
360
360
|
if (options.maxWidth != null && (!Number.isFinite(options.maxWidth) || !Number.isInteger(options.maxWidth))) throw new TypeError(`maxWidth must be a finite integer, got ${options.maxWidth}.`);
|
|
361
361
|
const filteredSections = page.sections.map((s) => ({
|
|
362
362
|
...s,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_internal_command_doc_policy = require('./internal/command-doc-policy.cjs');
|
|
1
2
|
const require_short_option = require('./short-option.cjs');
|
|
2
3
|
|
|
3
4
|
//#region src/execution-context.ts
|
|
@@ -19,7 +20,7 @@ function withChildExecPath(exec, segment) {
|
|
|
19
20
|
function mergeChildExec(parent, child) {
|
|
20
21
|
if (parent == null) return child;
|
|
21
22
|
if (child == null) return parent;
|
|
22
|
-
return {
|
|
23
|
+
return require_internal_command_doc_policy.mergeCommandDocPolicy(parent, child, {
|
|
23
24
|
...parent,
|
|
24
25
|
trace: child.trace ?? parent.trace,
|
|
25
26
|
dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
|
|
@@ -27,7 +28,7 @@ function mergeChildExec(parent, child) {
|
|
|
27
28
|
commandPath: child.commandPath ?? parent.commandPath,
|
|
28
29
|
preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
|
|
29
30
|
excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Creates a child parser context while keeping flat and nested execution data
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mergeCommandDocPolicy } from "./internal/command-doc-policy.js";
|
|
1
2
|
import { withOptionScopeChild } from "./short-option.js";
|
|
2
3
|
|
|
3
4
|
//#region src/execution-context.ts
|
|
@@ -19,7 +20,7 @@ function withChildExecPath(exec, segment) {
|
|
|
19
20
|
function mergeChildExec(parent, child) {
|
|
20
21
|
if (parent == null) return child;
|
|
21
22
|
if (child == null) return parent;
|
|
22
|
-
return {
|
|
23
|
+
return mergeCommandDocPolicy(parent, child, {
|
|
23
24
|
...parent,
|
|
24
25
|
trace: child.trace ?? parent.trace,
|
|
25
26
|
dependencyRuntime: child.dependencyRuntime ?? parent.dependencyRuntime,
|
|
@@ -27,7 +28,7 @@ function mergeChildExec(parent, child) {
|
|
|
27
28
|
commandPath: child.commandPath ?? parent.commandPath,
|
|
28
29
|
preCompletedByParser: child.preCompletedByParser ?? parent.preCompletedByParser,
|
|
29
30
|
excludedSourceFields: child.excludedSourceFields ?? parent.excludedSourceFields
|
|
30
|
-
};
|
|
31
|
+
});
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Creates a child parser context while keeping flat and nested execution data
|
package/dist/facade.cjs
CHANGED
|
@@ -545,14 +545,13 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
545
545
|
if (completionParser) {
|
|
546
546
|
const displayName = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
|
|
547
547
|
const doc = require_internal_parser.getDocPage(completionParser, [displayName]);
|
|
548
|
-
if (doc) stderr(require_doc.formatDocPage(programName, doc, completionDocOptions({
|
|
548
|
+
if (doc) stderr(require_doc.formatDocPage(programName, withDocShowUsage(doc, showUsage), completionDocOptions({
|
|
549
549
|
messageFormatter,
|
|
550
550
|
theme,
|
|
551
551
|
colors,
|
|
552
552
|
maxWidth,
|
|
553
553
|
termWidth,
|
|
554
|
-
sectionOrder
|
|
555
|
-
showUsage
|
|
554
|
+
sectionOrder
|
|
556
555
|
})));
|
|
557
556
|
}
|
|
558
557
|
if (!wroteError) writeError();
|
|
@@ -1024,7 +1023,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1024
1023
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1025
1024
|
}, commandList, isTopLevel);
|
|
1026
1025
|
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1027
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc;
|
|
1026
|
+
const renderedDoc = withDocShowUsage(isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc, showUsage);
|
|
1028
1027
|
stdout(require_doc.formatDocPage(programName, renderedDoc, formatOptions({
|
|
1029
1028
|
messageFormatter,
|
|
1030
1029
|
theme,
|
|
@@ -1035,8 +1034,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1035
1034
|
showChoices,
|
|
1036
1035
|
showAliases,
|
|
1037
1036
|
showEnvironment,
|
|
1038
|
-
sectionOrder
|
|
1039
|
-
showUsage
|
|
1037
|
+
sectionOrder
|
|
1040
1038
|
})));
|
|
1041
1039
|
return onHelp(0, renderedDoc);
|
|
1042
1040
|
}
|
|
@@ -1103,7 +1101,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1103
1101
|
}, commandList, isTopLevel);
|
|
1104
1102
|
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? require_usage.normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1105
1103
|
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1106
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc;
|
|
1104
|
+
const renderedDoc = withDocShowUsage(isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc, showUsage);
|
|
1107
1105
|
stderr(require_doc.formatDocPage(programName, renderedDoc, formatOptions({
|
|
1108
1106
|
messageFormatter,
|
|
1109
1107
|
theme,
|
|
@@ -1114,8 +1112,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1114
1112
|
showChoices,
|
|
1115
1113
|
showAliases,
|
|
1116
1114
|
showEnvironment,
|
|
1117
|
-
sectionOrder
|
|
1118
|
-
showUsage
|
|
1115
|
+
sectionOrder
|
|
1119
1116
|
})));
|
|
1120
1117
|
}
|
|
1121
1118
|
if (effectiveAboveError === "usage") {
|
|
@@ -1223,6 +1220,13 @@ function runParserAsync(parser, programName, args, options) {
|
|
|
1223
1220
|
const result = runParser(parser, programName, args, options);
|
|
1224
1221
|
return Promise.resolve(result);
|
|
1225
1222
|
}
|
|
1223
|
+
function withDocShowUsage(page, fallback) {
|
|
1224
|
+
const showUsage = page.showUsage ?? fallback;
|
|
1225
|
+
return showUsage == null ? page : {
|
|
1226
|
+
...page,
|
|
1227
|
+
showUsage
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1226
1230
|
function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
1227
1231
|
const customUsageLine = typeof usageLine === "function" ? usageLine(require_usage.cloneUsage(defaultUsageLine)) : usageLine;
|
|
1228
1232
|
return {
|
package/dist/facade.d.cts
CHANGED
|
@@ -172,7 +172,8 @@ interface RunOptions<THelp, TError> {
|
|
|
172
172
|
*/
|
|
173
173
|
readonly showEnvironment?: boolean | ShowEnvironmentOptions;
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
175
|
+
* Default visibility of the usage synopsis in full help output.
|
|
176
|
+
* Command-level `showUsage` settings override this default.
|
|
176
177
|
*
|
|
177
178
|
* This affects help pages produced by `--help`, the help command, and
|
|
178
179
|
* `aboveError: "help"`. It does not suppress usage-only error preambles
|
|
@@ -242,8 +243,8 @@ interface RunOptions<THelp, TError> {
|
|
|
242
243
|
* page passed to {@link formatDocPage}. Treat the page as read-only.
|
|
243
244
|
* It includes runner-provided entries and root usage customization.
|
|
244
245
|
* Subcommand and meta-command help use the selected command's docs,
|
|
245
|
-
* with the run-level footer as a fallback.
|
|
246
|
-
*
|
|
246
|
+
* with the run-level footer as a fallback. The resolved `showUsage`
|
|
247
|
+
* default is included in the page; other formatting options remain separate.
|
|
247
248
|
*
|
|
248
249
|
* Handlers may ignore either argument. Wrappers that invoke this
|
|
249
250
|
* callback themselves must forward both arguments.
|
package/dist/facade.d.ts
CHANGED
|
@@ -172,7 +172,8 @@ interface RunOptions<THelp, TError> {
|
|
|
172
172
|
*/
|
|
173
173
|
readonly showEnvironment?: boolean | ShowEnvironmentOptions;
|
|
174
174
|
/**
|
|
175
|
-
*
|
|
175
|
+
* Default visibility of the usage synopsis in full help output.
|
|
176
|
+
* Command-level `showUsage` settings override this default.
|
|
176
177
|
*
|
|
177
178
|
* This affects help pages produced by `--help`, the help command, and
|
|
178
179
|
* `aboveError: "help"`. It does not suppress usage-only error preambles
|
|
@@ -242,8 +243,8 @@ interface RunOptions<THelp, TError> {
|
|
|
242
243
|
* page passed to {@link formatDocPage}. Treat the page as read-only.
|
|
243
244
|
* It includes runner-provided entries and root usage customization.
|
|
244
245
|
* Subcommand and meta-command help use the selected command's docs,
|
|
245
|
-
* with the run-level footer as a fallback.
|
|
246
|
-
*
|
|
246
|
+
* with the run-level footer as a fallback. The resolved `showUsage`
|
|
247
|
+
* default is included in the page; other formatting options remain separate.
|
|
247
248
|
*
|
|
248
249
|
* Handlers may ignore either argument. Wrappers that invoke this
|
|
249
250
|
* callback themselves must forward both arguments.
|
package/dist/facade.js
CHANGED
|
@@ -545,14 +545,13 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
545
545
|
if (completionParser) {
|
|
546
546
|
const displayName = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
|
|
547
547
|
const doc = getDocPage(completionParser, [displayName]);
|
|
548
|
-
if (doc) stderr(formatDocPage(programName, doc, completionDocOptions({
|
|
548
|
+
if (doc) stderr(formatDocPage(programName, withDocShowUsage(doc, showUsage), completionDocOptions({
|
|
549
549
|
messageFormatter,
|
|
550
550
|
theme,
|
|
551
551
|
colors,
|
|
552
552
|
maxWidth,
|
|
553
553
|
termWidth,
|
|
554
|
-
sectionOrder
|
|
555
|
-
showUsage
|
|
554
|
+
sectionOrder
|
|
556
555
|
})));
|
|
557
556
|
}
|
|
558
557
|
if (!wroteError) writeError();
|
|
@@ -1024,7 +1023,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1024
1023
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1025
1024
|
}, commandList, isTopLevel);
|
|
1026
1025
|
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1027
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc;
|
|
1026
|
+
const renderedDoc = withDocShowUsage(isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc, showUsage);
|
|
1028
1027
|
stdout(formatDocPage(programName, renderedDoc, formatOptions({
|
|
1029
1028
|
messageFormatter,
|
|
1030
1029
|
theme,
|
|
@@ -1035,8 +1034,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1035
1034
|
showChoices,
|
|
1036
1035
|
showAliases,
|
|
1037
1036
|
showEnvironment,
|
|
1038
|
-
sectionOrder
|
|
1039
|
-
showUsage
|
|
1037
|
+
sectionOrder
|
|
1040
1038
|
})));
|
|
1041
1039
|
return onHelp(0, renderedDoc);
|
|
1042
1040
|
}
|
|
@@ -1103,7 +1101,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1103
1101
|
}, commandList, isTopLevel);
|
|
1104
1102
|
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1105
1103
|
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1106
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc;
|
|
1104
|
+
const renderedDoc = withDocShowUsage(isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc, showUsage);
|
|
1107
1105
|
stderr(formatDocPage(programName, renderedDoc, formatOptions({
|
|
1108
1106
|
messageFormatter,
|
|
1109
1107
|
theme,
|
|
@@ -1114,8 +1112,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1114
1112
|
showChoices,
|
|
1115
1113
|
showAliases,
|
|
1116
1114
|
showEnvironment,
|
|
1117
|
-
sectionOrder
|
|
1118
|
-
showUsage
|
|
1115
|
+
sectionOrder
|
|
1119
1116
|
})));
|
|
1120
1117
|
}
|
|
1121
1118
|
if (effectiveAboveError === "usage") {
|
|
@@ -1223,6 +1220,13 @@ function runParserAsync(parser, programName, args, options) {
|
|
|
1223
1220
|
const result = runParser(parser, programName, args, options);
|
|
1224
1221
|
return Promise.resolve(result);
|
|
1225
1222
|
}
|
|
1223
|
+
function withDocShowUsage(page, fallback) {
|
|
1224
|
+
const showUsage = page.showUsage ?? fallback;
|
|
1225
|
+
return showUsage == null ? page : {
|
|
1226
|
+
...page,
|
|
1227
|
+
showUsage
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1226
1230
|
function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
1227
1231
|
const customUsageLine = typeof usageLine === "function" ? usageLine(cloneUsage(defaultUsageLine)) : usageLine;
|
|
1228
1232
|
return {
|