@optique/core 1.4.0-dev.2618 → 1.4.0-dev.2619
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 +146 -87
- package/dist/constructs.js +146 -87
- package/dist/execution-context.cjs +2 -1
- package/dist/execution-context.js +3 -1
- package/dist/extension.cjs +15 -0
- package/dist/extension.d.cts +12 -1
- package/dist/extension.d.ts +12 -1
- package/dist/extension.js +15 -1
- package/dist/facade.cjs +6 -140
- package/dist/facade.d.cts +2 -32
- package/dist/facade.d.ts +2 -32
- package/dist/facade.js +7 -141
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/modifiers.cjs +5 -4
- package/dist/modifiers.js +5 -4
- package/dist/primitives.cjs +69 -27
- package/dist/primitives.d.cts +3 -3
- package/dist/primitives.d.ts +3 -3
- package/dist/primitives.js +69 -27
- package/dist/short-option.cjs +311 -0
- package/dist/short-option.js +297 -0
- package/dist/usage-internals.cjs +73 -0
- package/dist/usage-internals.js +71 -1
- package/package.json +2 -2
- package/skills/optique/SKILL.md +12 -12
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_short_option = require('./short-option.cjs');
|
|
1
2
|
|
|
2
3
|
//#region src/execution-context.ts
|
|
3
4
|
/**
|
|
@@ -37,7 +38,7 @@ function withChildContext(context, segment, state, usage) {
|
|
|
37
38
|
const exec = withChildExecPath(context.exec, segment);
|
|
38
39
|
const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
|
|
39
40
|
return {
|
|
40
|
-
...context,
|
|
41
|
+
...require_short_option.withOptionScopeChild(context, segment),
|
|
41
42
|
state,
|
|
42
43
|
...usage != null ? { usage } : {},
|
|
43
44
|
...exec != null ? {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { withOptionScopeChild } from "./short-option.js";
|
|
2
|
+
|
|
1
3
|
//#region src/execution-context.ts
|
|
2
4
|
/**
|
|
3
5
|
* Appends a child parser segment to the current execution path.
|
|
@@ -36,7 +38,7 @@ function withChildContext(context, segment, state, usage) {
|
|
|
36
38
|
const exec = withChildExecPath(context.exec, segment);
|
|
37
39
|
const dependencyRegistry = context.dependencyRegistry ?? exec?.dependencyRegistry;
|
|
38
40
|
return {
|
|
39
|
-
...context,
|
|
41
|
+
...withOptionScopeChild(context, segment),
|
|
40
42
|
state,
|
|
41
43
|
...usage != null ? { usage } : {},
|
|
42
44
|
...exec != null ? {
|
package/dist/extension.cjs
CHANGED
|
@@ -2,6 +2,7 @@ const require_internal_annotations = require('./internal/annotations.cjs');
|
|
|
2
2
|
const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
|
|
3
3
|
const require_internal_parser = require('./internal/parser.cjs');
|
|
4
4
|
const require_annotation_state = require('./annotation-state.cjs');
|
|
5
|
+
const require_short_option = require('./short-option.cjs');
|
|
5
6
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
6
7
|
|
|
7
8
|
//#region src/extension.ts
|
|
@@ -28,6 +29,19 @@ function defineTraits(parser, traits) {
|
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
32
|
+
* Preserves a wrapped parser's reachable option names in the same parse path.
|
|
33
|
+
* Call this when a transparent wrapper constructs a fresh parser object instead
|
|
34
|
+
* of copying the inner parser with object spread.
|
|
35
|
+
*
|
|
36
|
+
* @param parser The wrapper parser to annotate.
|
|
37
|
+
* @param innerParser The parser that handles the wrapper's CLI input.
|
|
38
|
+
* @throws {TypeError} If scope metadata cannot be defined on the wrapper.
|
|
39
|
+
* @since 1.4.0
|
|
40
|
+
*/
|
|
41
|
+
function inheritOptionScope$1(parser, innerParser) {
|
|
42
|
+
require_short_option.inheritOptionScope(parser, innerParser);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
31
45
|
* Reads the stable extension traits defined on a parser object.
|
|
32
46
|
*
|
|
33
47
|
* @param parser The parser object to inspect.
|
|
@@ -80,6 +94,7 @@ exports.dispatchByMode = require_mode_dispatch.dispatchByMode;
|
|
|
80
94
|
exports.extractPhase2SeedKey = require_phase2_seed.extractPhase2SeedKey;
|
|
81
95
|
exports.getTraits = getTraits;
|
|
82
96
|
exports.inheritAnnotations = require_internal_annotations.inheritAnnotations;
|
|
97
|
+
exports.inheritOptionScope = inheritOptionScope$1;
|
|
83
98
|
exports.injectAnnotations = require_internal_annotations.injectAnnotations;
|
|
84
99
|
exports.isInjectedAnnotationState = require_internal_annotations.isInjectedAnnotationState;
|
|
85
100
|
exports.mapModeValue = require_mode_dispatch.mapModeValue;
|
package/dist/extension.d.cts
CHANGED
|
@@ -60,6 +60,17 @@ type ParserSourceMetadata<M extends Mode = Mode, TValue = unknown, TState = unkn
|
|
|
60
60
|
* @since 1.0.0
|
|
61
61
|
*/
|
|
62
62
|
declare function defineTraits(parser: object, traits: ParserTraits): void;
|
|
63
|
+
/**
|
|
64
|
+
* Preserves a wrapped parser's reachable option names in the same parse path.
|
|
65
|
+
* Call this when a transparent wrapper constructs a fresh parser object instead
|
|
66
|
+
* of copying the inner parser with object spread.
|
|
67
|
+
*
|
|
68
|
+
* @param parser The wrapper parser to annotate.
|
|
69
|
+
* @param innerParser The parser that handles the wrapper's CLI input.
|
|
70
|
+
* @throws {TypeError} If scope metadata cannot be defined on the wrapper.
|
|
71
|
+
* @since 1.4.0
|
|
72
|
+
*/
|
|
73
|
+
declare function inheritOptionScope(parser: object, innerParser: Parser<Mode, unknown, unknown>): void;
|
|
63
74
|
/**
|
|
64
75
|
* Reads the stable extension traits defined on a parser object.
|
|
65
76
|
*
|
|
@@ -95,4 +106,4 @@ declare function delegateSuggestNodes<TInnerState>(innerParser: Parser<Mode, unk
|
|
|
95
106
|
*/
|
|
96
107
|
declare function mapSourceMetadata<M extends Mode, TValue, TState>(parser: Pick<Parser<M, TValue, TState>, "dependencyMetadata">, mapSource: (source: ParserSourceMetadata<M, TValue, TState>) => ParserSourceMetadata<M, TValue, TState>): Parser<M, TValue, TState>["dependencyMetadata"] | undefined;
|
|
97
108
|
//#endregion
|
|
98
|
-
export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, extractPhase2SeedKey, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
|
109
|
+
export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, extractPhase2SeedKey, getTraits, inheritAnnotations, inheritOptionScope, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
package/dist/extension.d.ts
CHANGED
|
@@ -60,6 +60,17 @@ type ParserSourceMetadata<M extends Mode = Mode, TValue = unknown, TState = unkn
|
|
|
60
60
|
* @since 1.0.0
|
|
61
61
|
*/
|
|
62
62
|
declare function defineTraits(parser: object, traits: ParserTraits): void;
|
|
63
|
+
/**
|
|
64
|
+
* Preserves a wrapped parser's reachable option names in the same parse path.
|
|
65
|
+
* Call this when a transparent wrapper constructs a fresh parser object instead
|
|
66
|
+
* of copying the inner parser with object spread.
|
|
67
|
+
*
|
|
68
|
+
* @param parser The wrapper parser to annotate.
|
|
69
|
+
* @param innerParser The parser that handles the wrapper's CLI input.
|
|
70
|
+
* @throws {TypeError} If scope metadata cannot be defined on the wrapper.
|
|
71
|
+
* @since 1.4.0
|
|
72
|
+
*/
|
|
73
|
+
declare function inheritOptionScope(parser: object, innerParser: Parser<Mode, unknown, unknown>): void;
|
|
63
74
|
/**
|
|
64
75
|
* Reads the stable extension traits defined on a parser object.
|
|
65
76
|
*
|
|
@@ -95,4 +106,4 @@ declare function delegateSuggestNodes<TInnerState>(innerParser: Parser<Mode, unk
|
|
|
95
106
|
*/
|
|
96
107
|
declare function mapSourceMetadata<M extends Mode, TValue, TState>(parser: Pick<Parser<M, TValue, TState>, "dependencyMetadata">, mapSource: (source: ParserSourceMetadata<M, TValue, TState>) => ParserSourceMetadata<M, TValue, TState>): Parser<M, TValue, TState>["dependencyMetadata"] | undefined;
|
|
97
108
|
//#endregion
|
|
98
|
-
export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, extractPhase2SeedKey, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
|
109
|
+
export { ParserSourceMetadata, ParserTraits, SuggestNode, defineTraits, delegateSuggestNodes, dispatchByMode, extractPhase2SeedKey, getTraits, inheritAnnotations, inheritOptionScope, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
package/dist/extension.js
CHANGED
|
@@ -2,6 +2,7 @@ import { inheritAnnotations, injectAnnotations, isInjectedAnnotationState, unwra
|
|
|
2
2
|
import { dispatchByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
|
|
3
3
|
import { annotationWrapperRequiresSourceBindingKey, composeWrappedSourceMetadata, defineInheritedAnnotationParser, getDelegatingSuggestRuntimeNodes, inheritParentAnnotationsKey, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
|
|
4
4
|
import { withAnnotationView } from "./annotation-state.js";
|
|
5
|
+
import { inheritOptionScope } from "./short-option.js";
|
|
5
6
|
import { extractPhase2SeedKey } from "./phase2-seed.js";
|
|
6
7
|
|
|
7
8
|
//#region src/extension.ts
|
|
@@ -28,6 +29,19 @@ function defineTraits(parser, traits) {
|
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
32
|
+
* Preserves a wrapped parser's reachable option names in the same parse path.
|
|
33
|
+
* Call this when a transparent wrapper constructs a fresh parser object instead
|
|
34
|
+
* of copying the inner parser with object spread.
|
|
35
|
+
*
|
|
36
|
+
* @param parser The wrapper parser to annotate.
|
|
37
|
+
* @param innerParser The parser that handles the wrapper's CLI input.
|
|
38
|
+
* @throws {TypeError} If scope metadata cannot be defined on the wrapper.
|
|
39
|
+
* @since 1.4.0
|
|
40
|
+
*/
|
|
41
|
+
function inheritOptionScope$1(parser, innerParser) {
|
|
42
|
+
inheritOptionScope(parser, innerParser);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
31
45
|
* Reads the stable extension traits defined on a parser object.
|
|
32
46
|
*
|
|
33
47
|
* @param parser The parser object to inspect.
|
|
@@ -74,4 +88,4 @@ function mapSourceMetadata(parser, mapSource) {
|
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
//#endregion
|
|
77
|
-
export { defineTraits, delegateSuggestNodes, dispatchByMode, extractPhase2SeedKey, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
|
91
|
+
export { defineTraits, delegateSuggestNodes, dispatchByMode, extractPhase2SeedKey, getTraits, inheritAnnotations, inheritOptionScope$1 as inheritOptionScope, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, unwrapInjectedAnnotationState, withAnnotationView, wrapForMode };
|
package/dist/facade.cjs
CHANGED
|
@@ -12,6 +12,7 @@ const require_dependency_runtime = require('./dependency-runtime.cjs');
|
|
|
12
12
|
const require_input_trace = require('./input-trace.cjs');
|
|
13
13
|
const require_internal_parser = require('./internal/parser.cjs');
|
|
14
14
|
const require_completion = require('./completion.cjs');
|
|
15
|
+
const require_usage_internals = require('./usage-internals.cjs');
|
|
15
16
|
const require_command_alias = require('./internal/command-alias.cjs');
|
|
16
17
|
const require_phase2_seed = require('./phase2-seed.cjs');
|
|
17
18
|
const require_modifiers = require('./modifiers.cjs');
|
|
@@ -750,83 +751,16 @@ function collectActiveValueOptionNames(usage, commandPath, includeDirectAfterCom
|
|
|
750
751
|
flag: /* @__PURE__ */ new Set()
|
|
751
752
|
};
|
|
752
753
|
if (commandPath.length === 0) {
|
|
753
|
-
collectRootOptionNames(usage, optionNames, rootLeadingNames);
|
|
754
|
+
require_usage_internals.collectRootOptionNames(usage, optionNames, rootLeadingNames);
|
|
754
755
|
return optionNames.value;
|
|
755
|
-
} else collectActiveOptionNames(usage, commandPath, optionNames, false, includeDirectAfterCommandOptions);
|
|
756
|
+
} else require_usage_internals.collectActiveOptionNames(usage, commandPath, optionNames, false, includeDirectAfterCommandOptions);
|
|
756
757
|
const names = new Set(optionNames.value);
|
|
757
758
|
for (const name of optionNames.flag) names.delete(name);
|
|
758
759
|
return names;
|
|
759
760
|
}
|
|
760
|
-
function collectRootOptionNames(usage, names, rootLeadingNames) {
|
|
761
|
-
for (const term of usage) collectRootOptionNamesFromTerm(term, names, rootLeadingNames);
|
|
762
|
-
}
|
|
763
|
-
function collectRootOptionNamesFromTerm(term, names, rootLeadingNames) {
|
|
764
|
-
switch (term.type) {
|
|
765
|
-
case "option":
|
|
766
|
-
for (const name of term.names) {
|
|
767
|
-
if (!rootLeadingNames.has(name)) continue;
|
|
768
|
-
if (term.metavar != null) names.value.add(name);
|
|
769
|
-
else names.flag.add(name);
|
|
770
|
-
}
|
|
771
|
-
return;
|
|
772
|
-
case "optional":
|
|
773
|
-
case "multiple":
|
|
774
|
-
case "sequence":
|
|
775
|
-
collectRootOptionNames(term.terms, names, rootLeadingNames);
|
|
776
|
-
return;
|
|
777
|
-
case "exclusive":
|
|
778
|
-
for (const branch of term.terms) collectRootOptionNames(branch, names, rootLeadingNames);
|
|
779
|
-
return;
|
|
780
|
-
case "argument":
|
|
781
|
-
case "command":
|
|
782
|
-
case "literal":
|
|
783
|
-
case "passthrough":
|
|
784
|
-
case "ellipsis": return;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
function collectActiveOptionNames(usage, commandPath, names, fromExclusive, includeDirectAfterCommandOptions) {
|
|
788
|
-
if (commandPath.length === 0) {
|
|
789
|
-
collectOptionNamesAtCurrentCommandDepth(usage, names, false);
|
|
790
|
-
return;
|
|
791
|
-
}
|
|
792
|
-
const [commandName, ...rest] = commandPath;
|
|
793
|
-
for (let i = 0; i < usage.length; i++) {
|
|
794
|
-
const term = usage[i];
|
|
795
|
-
if (term.type === "command" && term.name === commandName) {
|
|
796
|
-
const remainingUsage = usage.slice(i + 1);
|
|
797
|
-
if (rest.length === 0) collectOptionNamesAtCurrentCommandDepth(remainingUsage, names, !fromExclusive && includeDirectAfterCommandOptions);
|
|
798
|
-
else collectActiveOptionNames(remainingUsage, rest, names, fromExclusive, includeDirectAfterCommandOptions);
|
|
799
|
-
} else if (term.type === "exclusive") for (const branch of term.terms) collectActiveOptionNames(branch, commandPath, names, true, includeDirectAfterCommandOptions);
|
|
800
|
-
else if (term.type === "optional" || term.type === "multiple" || term.type === "sequence") collectActiveOptionNames(term.terms, commandPath, names, fromExclusive, includeDirectAfterCommandOptions);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
761
|
function isRootOptionToken(token, rootOptionSuggestions) {
|
|
804
762
|
return token != null && rootOptionSuggestions.some((suggestion) => token === suggestion.text || token.startsWith(`${suggestion.text}=`));
|
|
805
763
|
}
|
|
806
|
-
function collectOptionNamesAtCurrentCommandDepth(usage, names, afterMatchedCommand) {
|
|
807
|
-
for (const term of usage) if (collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand)) return;
|
|
808
|
-
}
|
|
809
|
-
function collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand) {
|
|
810
|
-
switch (term.type) {
|
|
811
|
-
case "command": return !afterMatchedCommand;
|
|
812
|
-
case "option":
|
|
813
|
-
if (term.metavar != null) for (const name of term.names) names.value.add(name);
|
|
814
|
-
else for (const name of term.names) names.flag.add(name);
|
|
815
|
-
return false;
|
|
816
|
-
case "optional":
|
|
817
|
-
case "multiple":
|
|
818
|
-
case "sequence":
|
|
819
|
-
collectOptionNamesAtCurrentCommandDepth(term.terms, names, afterMatchedCommand);
|
|
820
|
-
return false;
|
|
821
|
-
case "exclusive":
|
|
822
|
-
for (const branch of term.terms) collectOptionNamesAtCurrentCommandDepth(branch, names, false);
|
|
823
|
-
return false;
|
|
824
|
-
case "argument":
|
|
825
|
-
case "literal":
|
|
826
|
-
case "passthrough":
|
|
827
|
-
case "ellipsis": return false;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
764
|
function getRootMetaOptionSuggestions(helpOptionConfig, helpOptionNames, versionOptionConfig, versionOptionNames) {
|
|
831
765
|
const suggestions = [];
|
|
832
766
|
if (helpOptionConfig != null && !require_usage.isSuggestionHidden(helpOptionConfig.hidden)) suggestions.push(...helpOptionNames.map((name) => ({
|
|
@@ -884,7 +818,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
884
818
|
options = optionsParam ?? {};
|
|
885
819
|
}
|
|
886
820
|
require_validate.validateProgramName(programName);
|
|
887
|
-
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder,
|
|
821
|
+
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
888
822
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
889
823
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
890
824
|
let maxWidth = requestedMaxWidth;
|
|
@@ -916,7 +850,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
916
850
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
917
851
|
const onCompletionResult = (code) => onCompletion(code);
|
|
918
852
|
const onErrorResult = (code, error) => onError(code, error);
|
|
919
|
-
for (const label of [helpSections?.commands, helpSections?.options]) if (label !== void 0) require_validate.validateLabel(label);
|
|
920
853
|
if (helpOptionConfig?.names) require_validate.validateOptionNames(helpOptionConfig.names, "Help option");
|
|
921
854
|
if (helpCommandConfig?.names) require_validate.validateCommandNames(helpCommandConfig.names, "Help command");
|
|
922
855
|
if (versionOptionConfig?.names) require_validate.validateOptionNames(versionOptionConfig.names, "Version option");
|
|
@@ -1089,8 +1022,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1089
1022
|
bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
|
|
1090
1023
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1091
1024
|
}, commandList, isTopLevel);
|
|
1092
|
-
const
|
|
1093
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc;
|
|
1025
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine) : augmentedDoc;
|
|
1094
1026
|
stdout(require_doc.formatDocPage(programName, renderedDoc, formatOptions({
|
|
1095
1027
|
messageFormatter,
|
|
1096
1028
|
theme,
|
|
@@ -1166,8 +1098,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1166
1098
|
footer: footer ?? doc.footer
|
|
1167
1099
|
}, commandList, isTopLevel);
|
|
1168
1100
|
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? require_usage.normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1169
|
-
const
|
|
1170
|
-
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc;
|
|
1101
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine, defaultRootUsage) : augmentedDoc;
|
|
1171
1102
|
stderr(require_doc.formatDocPage(programName, renderedDoc, formatOptions({
|
|
1172
1103
|
messageFormatter,
|
|
1173
1104
|
theme,
|
|
@@ -1254,7 +1185,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1254
1185
|
* @returns The parsed result if successful.
|
|
1255
1186
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
1256
1187
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
1257
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1258
1188
|
* @since 0.9.0
|
|
1259
1189
|
*/
|
|
1260
1190
|
function runParserSync(parser, programName, args, options) {
|
|
@@ -1277,7 +1207,6 @@ function runParserSync(parser, programName, args, options) {
|
|
|
1277
1207
|
* @param options Configuration options for customizing behavior.
|
|
1278
1208
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1279
1209
|
* color, even when colors are disabled.
|
|
1280
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1281
1210
|
* @returns A Promise of the parsed result if successful.
|
|
1282
1211
|
* @since 0.9.0
|
|
1283
1212
|
*/
|
|
@@ -1292,66 +1221,6 @@ function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
|
1292
1221
|
usage: require_usage.normalizeUsage(customUsageLine)
|
|
1293
1222
|
};
|
|
1294
1223
|
}
|
|
1295
|
-
/** Prepares the runner's final page without changing parser documentation. */
|
|
1296
|
-
function applyHelpSections(doc, labels) {
|
|
1297
|
-
if (labels == null || labels.commands == null && labels.options == null) return doc;
|
|
1298
|
-
const visible = (entry) => !require_doc.isDocEntryHidden(entry) && require_usage.formatUsageTerm(entry.term, { context: "doc" }).trim() !== "";
|
|
1299
|
-
if (!doc.sections.some((section) => section.entries.some((entry) => entry.term.type === "command" && visible(entry)))) return doc;
|
|
1300
|
-
const existingTitles = new Set(doc.sections.flatMap((section) => section.title == null ? [] : [section.title]));
|
|
1301
|
-
const additions = /* @__PURE__ */ new Map();
|
|
1302
|
-
const residuals = /* @__PURE__ */ new Map();
|
|
1303
|
-
const newSections = /* @__PURE__ */ new Map();
|
|
1304
|
-
for (const section of doc.sections) {
|
|
1305
|
-
if (section.title != null) continue;
|
|
1306
|
-
const commands = [];
|
|
1307
|
-
const options = [];
|
|
1308
|
-
const remaining = [];
|
|
1309
|
-
for (const entry of section.entries) if (entry.term.type === "command" && labels.commands != null && visible(entry)) commands.push(entry);
|
|
1310
|
-
else if (entry.term.type === "option" && labels.options != null && visible(entry)) options.push(entry);
|
|
1311
|
-
else remaining.push(entry);
|
|
1312
|
-
if (commands.length === 0 && options.length === 0) continue;
|
|
1313
|
-
residuals.set(section, remaining);
|
|
1314
|
-
for (const [label, entries] of [[labels.commands, commands], [labels.options, options]]) {
|
|
1315
|
-
if (label == null || entries.length === 0) continue;
|
|
1316
|
-
const previous = additions.get(label);
|
|
1317
|
-
if (previous != null) previous.push(...entries);
|
|
1318
|
-
else {
|
|
1319
|
-
additions.set(label, entries);
|
|
1320
|
-
if (!existingTitles.has(label)) {
|
|
1321
|
-
const titles = newSections.get(section) ?? [];
|
|
1322
|
-
titles.push(label);
|
|
1323
|
-
newSections.set(section, titles);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
if (additions.size === 0) return doc;
|
|
1329
|
-
const sections = [];
|
|
1330
|
-
for (const section of doc.sections) {
|
|
1331
|
-
if (section.title != null) {
|
|
1332
|
-
const entries$1 = additions.get(section.title);
|
|
1333
|
-
sections.push(entries$1 == null ? section : {
|
|
1334
|
-
...section,
|
|
1335
|
-
entries: [...section.entries, ...entries$1]
|
|
1336
|
-
});
|
|
1337
|
-
continue;
|
|
1338
|
-
}
|
|
1339
|
-
for (const title of newSections.get(section) ?? []) sections.push({
|
|
1340
|
-
title,
|
|
1341
|
-
entries: additions.get(title) ?? []
|
|
1342
|
-
});
|
|
1343
|
-
const entries = residuals.get(section);
|
|
1344
|
-
if (entries == null) sections.push(section);
|
|
1345
|
-
else if (entries.length > 0) sections.push({
|
|
1346
|
-
...section,
|
|
1347
|
-
entries
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
return {
|
|
1351
|
-
...doc,
|
|
1352
|
-
sections
|
|
1353
|
-
};
|
|
1354
|
-
}
|
|
1355
1224
|
function maybeCollapseCommandList(doc, commandList, isTopLevel) {
|
|
1356
1225
|
if (commandList !== "top-level" || !isTopLevel) return doc;
|
|
1357
1226
|
return {
|
|
@@ -1687,7 +1556,6 @@ async function runWithBody(parser, programName, contexts, args, options) {
|
|
|
1687
1556
|
* @param programName Name of the program for help/error output.
|
|
1688
1557
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1689
1558
|
* @param options Run options including args, help, version, etc.
|
|
1690
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1691
1559
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1692
1560
|
* color, even when colors are disabled.
|
|
1693
1561
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -1788,7 +1656,6 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
|
|
|
1788
1656
|
* @param programName Name of the program for help/error output.
|
|
1789
1657
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1790
1658
|
* @param options Run options including args, help, version, etc.
|
|
1791
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1792
1659
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1793
1660
|
* color, even when colors are disabled.
|
|
1794
1661
|
* @returns The parsed result.
|
|
@@ -1840,7 +1707,6 @@ function runWithSync(parser, programName, contexts, options) {
|
|
|
1840
1707
|
* @param programName Name of the program for help/error output.
|
|
1841
1708
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1842
1709
|
* @param options Run options including args, help, version, etc.
|
|
1843
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1844
1710
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1845
1711
|
* color, even when colors are disabled.
|
|
1846
1712
|
* @returns Promise that resolves to the parsed result.
|
package/dist/facade.d.cts
CHANGED
|
@@ -20,19 +20,6 @@ import { Program } from "./program.cjs";
|
|
|
20
20
|
* @since 1.2.0
|
|
21
21
|
*/
|
|
22
22
|
type CommandListMode = "recursive" | "top-level";
|
|
23
|
-
/**
|
|
24
|
-
* Labels for automatically grouping untitled help entries on pages that
|
|
25
|
-
* contain visible commands. Explicitly titled sections keep their titles.
|
|
26
|
-
* Missing labels leave the corresponding entries untitled.
|
|
27
|
-
*
|
|
28
|
-
* @since 1.4.0
|
|
29
|
-
*/
|
|
30
|
-
interface HelpSectionsOptions {
|
|
31
|
-
/** Heading for untitled command entries. */
|
|
32
|
-
readonly commands?: string;
|
|
33
|
-
/** Heading for untitled option entries, including built-in meta options. */
|
|
34
|
-
readonly options?: string;
|
|
35
|
-
}
|
|
36
23
|
/**
|
|
37
24
|
* Sub-configuration for a meta command's command form.
|
|
38
25
|
*
|
|
@@ -197,16 +184,6 @@ interface RunOptions<THelp, TError> {
|
|
|
197
184
|
* @since 1.0.0
|
|
198
185
|
*/
|
|
199
186
|
readonly sectionOrder?: (a: DocSection, b: DocSection) => number;
|
|
200
|
-
/**
|
|
201
|
-
* Groups untitled command and option entries when the help page contains
|
|
202
|
-
* visible commands. Pages without commands receive no automatic headings.
|
|
203
|
-
* Existing titled sections are preserved; matching automatic entries are
|
|
204
|
-
* appended to them. Applies to help callbacks and help above errors too.
|
|
205
|
-
* Supplied labels must be nonempty and contain no control characters.
|
|
206
|
-
*
|
|
207
|
-
* @since 1.4.0
|
|
208
|
-
*/
|
|
209
|
-
readonly helpSections?: HelpSectionsOptions;
|
|
210
187
|
/**
|
|
211
188
|
* Help configuration. When provided, enables help functionality.
|
|
212
189
|
* At least one of `command` or `option` must be specified.
|
|
@@ -405,9 +382,7 @@ interface RunOptions<THelp, TError> {
|
|
|
405
382
|
* non-empty string without ASCII control characters, or if any
|
|
406
383
|
* meta command/option name is empty, whitespace-only, contains
|
|
407
384
|
* whitespace or control characters, or (for option names) lacks a
|
|
408
|
-
* valid prefix (`--`, `-`, `/`, or `+`).
|
|
409
|
-
* `helpSections` label is empty, whitespace-only, or contains
|
|
410
|
-
* control characters.
|
|
385
|
+
* valid prefix (`--`, `-`, `/`, or `+`).
|
|
411
386
|
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
412
387
|
* provided, or if the requested help page cannot be generated.
|
|
413
388
|
* @since 0.10.0 Added support for {@link Program} objects.
|
|
@@ -436,7 +411,6 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
|
|
|
436
411
|
* @returns The parsed result if successful.
|
|
437
412
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
438
413
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
439
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
440
414
|
* @since 0.9.0
|
|
441
415
|
*/
|
|
442
416
|
declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
@@ -456,7 +430,6 @@ declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>,
|
|
|
456
430
|
* @param options Configuration options for customizing behavior.
|
|
457
431
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
458
432
|
* color, even when colors are disabled.
|
|
459
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
460
433
|
* @returns A Promise of the parsed result if successful.
|
|
461
434
|
* @since 0.9.0
|
|
462
435
|
*/
|
|
@@ -571,7 +544,6 @@ type ContextOptionsParam<TContexts extends readonly SourceContext<unknown>[], TV
|
|
|
571
544
|
* @param programName Name of the program for help/error output.
|
|
572
545
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
573
546
|
* @param options Run options including args, help, version, etc.
|
|
574
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
575
547
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
576
548
|
* color, even when colors are disabled.
|
|
577
549
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -623,7 +595,6 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
|
|
|
623
595
|
* @param programName Name of the program for help/error output.
|
|
624
596
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
625
597
|
* @param options Run options including args, help, version, etc.
|
|
626
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
627
598
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
628
599
|
* color, even when colors are disabled.
|
|
629
600
|
* @returns The parsed result.
|
|
@@ -654,7 +625,6 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
654
625
|
* @param programName Name of the program for help/error output.
|
|
655
626
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
656
627
|
* @param options Run options including args, help, version, etc.
|
|
657
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
658
628
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
659
629
|
* color, even when colors are disabled.
|
|
660
630
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -667,4 +637,4 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
667
637
|
*/
|
|
668
638
|
declare function runWithAsync<TParser extends Parser<Mode, unknown, unknown>, TContexts extends readonly SourceContext<unknown>[], THelp = void, TError = never>(parser: TParser, programName: string, contexts: TContexts, options: RunWithOptions<THelp, TError> & ContextOptionsParam<TContexts, InferValue<TParser>>): Promise<InferValue<TParser>>;
|
|
669
639
|
//#endregion
|
|
670
|
-
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions,
|
|
640
|
+
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, type SourceContextRequest, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
package/dist/facade.d.ts
CHANGED
|
@@ -20,19 +20,6 @@ import { Program } from "./program.js";
|
|
|
20
20
|
* @since 1.2.0
|
|
21
21
|
*/
|
|
22
22
|
type CommandListMode = "recursive" | "top-level";
|
|
23
|
-
/**
|
|
24
|
-
* Labels for automatically grouping untitled help entries on pages that
|
|
25
|
-
* contain visible commands. Explicitly titled sections keep their titles.
|
|
26
|
-
* Missing labels leave the corresponding entries untitled.
|
|
27
|
-
*
|
|
28
|
-
* @since 1.4.0
|
|
29
|
-
*/
|
|
30
|
-
interface HelpSectionsOptions {
|
|
31
|
-
/** Heading for untitled command entries. */
|
|
32
|
-
readonly commands?: string;
|
|
33
|
-
/** Heading for untitled option entries, including built-in meta options. */
|
|
34
|
-
readonly options?: string;
|
|
35
|
-
}
|
|
36
23
|
/**
|
|
37
24
|
* Sub-configuration for a meta command's command form.
|
|
38
25
|
*
|
|
@@ -197,16 +184,6 @@ interface RunOptions<THelp, TError> {
|
|
|
197
184
|
* @since 1.0.0
|
|
198
185
|
*/
|
|
199
186
|
readonly sectionOrder?: (a: DocSection, b: DocSection) => number;
|
|
200
|
-
/**
|
|
201
|
-
* Groups untitled command and option entries when the help page contains
|
|
202
|
-
* visible commands. Pages without commands receive no automatic headings.
|
|
203
|
-
* Existing titled sections are preserved; matching automatic entries are
|
|
204
|
-
* appended to them. Applies to help callbacks and help above errors too.
|
|
205
|
-
* Supplied labels must be nonempty and contain no control characters.
|
|
206
|
-
*
|
|
207
|
-
* @since 1.4.0
|
|
208
|
-
*/
|
|
209
|
-
readonly helpSections?: HelpSectionsOptions;
|
|
210
187
|
/**
|
|
211
188
|
* Help configuration. When provided, enables help functionality.
|
|
212
189
|
* At least one of `command` or `option` must be specified.
|
|
@@ -405,9 +382,7 @@ interface RunOptions<THelp, TError> {
|
|
|
405
382
|
* non-empty string without ASCII control characters, or if any
|
|
406
383
|
* meta command/option name is empty, whitespace-only, contains
|
|
407
384
|
* whitespace or control characters, or (for option names) lacks a
|
|
408
|
-
* valid prefix (`--`, `-`, `/`, or `+`).
|
|
409
|
-
* `helpSections` label is empty, whitespace-only, or contains
|
|
410
|
-
* control characters.
|
|
385
|
+
* valid prefix (`--`, `-`, `/`, or `+`).
|
|
411
386
|
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
412
387
|
* provided, or if the requested help page cannot be generated.
|
|
413
388
|
* @since 0.10.0 Added support for {@link Program} objects.
|
|
@@ -436,7 +411,6 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
|
|
|
436
411
|
* @returns The parsed result if successful.
|
|
437
412
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
438
413
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
439
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
440
414
|
* @since 0.9.0
|
|
441
415
|
*/
|
|
442
416
|
declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>, THelp = void, TError = never>(parser: TParser, programName: string, args: readonly string[], options?: RunOptions<THelp, TError>): InferValue<TParser>;
|
|
@@ -456,7 +430,6 @@ declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>,
|
|
|
456
430
|
* @param options Configuration options for customizing behavior.
|
|
457
431
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
458
432
|
* color, even when colors are disabled.
|
|
459
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
460
433
|
* @returns A Promise of the parsed result if successful.
|
|
461
434
|
* @since 0.9.0
|
|
462
435
|
*/
|
|
@@ -571,7 +544,6 @@ type ContextOptionsParam<TContexts extends readonly SourceContext<unknown>[], TV
|
|
|
571
544
|
* @param programName Name of the program for help/error output.
|
|
572
545
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
573
546
|
* @param options Run options including args, help, version, etc.
|
|
574
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
575
547
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
576
548
|
* color, even when colors are disabled.
|
|
577
549
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -623,7 +595,6 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
|
|
|
623
595
|
* @param programName Name of the program for help/error output.
|
|
624
596
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
625
597
|
* @param options Run options including args, help, version, etc.
|
|
626
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
627
598
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
628
599
|
* color, even when colors are disabled.
|
|
629
600
|
* @returns The parsed result.
|
|
@@ -654,7 +625,6 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
654
625
|
* @param programName Name of the program for help/error output.
|
|
655
626
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
656
627
|
* @param options Run options including args, help, version, etc.
|
|
657
|
-
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
658
628
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
659
629
|
* color, even when colors are disabled.
|
|
660
630
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -667,4 +637,4 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
667
637
|
*/
|
|
668
638
|
declare function runWithAsync<TParser extends Parser<Mode, unknown, unknown>, TContexts extends readonly SourceContext<unknown>[], THelp = void, TError = never>(parser: TParser, programName: string, contexts: TContexts, options: RunWithOptions<THelp, TError> & ContextOptionsParam<TContexts, InferValue<TParser>>): Promise<InferValue<TParser>>;
|
|
669
639
|
//#endregion
|
|
670
|
-
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions,
|
|
640
|
+
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, type SourceContextRequest, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|