@optique/core 1.3.0-dev.2352 → 1.3.0-dev.2353
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/facade.cjs +51 -37
- package/dist/facade.d.cts +15 -1
- package/dist/facade.d.ts +15 -1
- package/dist/facade.js +52 -38
- package/package.json +2 -2
- package/skills/optique/SKILL.md +3 -0
package/dist/facade.cjs
CHANGED
|
@@ -952,7 +952,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
952
952
|
options = optionsParam ?? {};
|
|
953
953
|
}
|
|
954
954
|
require_validate.validateProgramName(programName);
|
|
955
|
-
const { colors, maxWidth, showDefault, showChoices, sectionOrder, showUsage, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
955
|
+
const { colors, maxWidth, showDefault, showChoices, sectionOrder, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
956
956
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
957
957
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
958
958
|
const norm = (c) => c === true ? {} : c;
|
|
@@ -1045,6 +1045,41 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1045
1045
|
completionCommandGroup: completionCommandConfig?.group,
|
|
1046
1046
|
completionOptionGroup: completionOptionConfig?.group
|
|
1047
1047
|
});
|
|
1048
|
+
const helpAsCommand = helpCommandConfig != null;
|
|
1049
|
+
const versionAsCommand = versionCommandConfig != null;
|
|
1050
|
+
const completionAsCommand = completionCommandConfig != null;
|
|
1051
|
+
const helpAsOption = helpOptionConfig != null;
|
|
1052
|
+
const versionAsOption = versionOptionConfig != null;
|
|
1053
|
+
const completionAsOption = completionOptionConfig != null;
|
|
1054
|
+
let cachedRootHelpGeneratorParser;
|
|
1055
|
+
const getRootHelpGeneratorParser = () => {
|
|
1056
|
+
if (cachedRootHelpGeneratorParser != null) return cachedRootHelpGeneratorParser;
|
|
1057
|
+
const commandParsers = [parser];
|
|
1058
|
+
const groupedMeta = {};
|
|
1059
|
+
const ungroupedMeta = [];
|
|
1060
|
+
const addMeta = (metaParser, groupLabel) => {
|
|
1061
|
+
if (groupLabel) (groupedMeta[groupLabel] ??= []).push(metaParser);
|
|
1062
|
+
else ungroupedMeta.push(metaParser);
|
|
1063
|
+
};
|
|
1064
|
+
if (helpAsCommand && helpParsers.helpCommand) addMeta(helpParsers.helpCommand, helpCommandConfig?.group);
|
|
1065
|
+
if (versionAsCommand && versionParsers.versionCommand) addMeta(versionParsers.versionCommand, versionCommandConfig?.group);
|
|
1066
|
+
if (completionAsCommand && completionParsers.completionCommand) addMeta(completionParsers.completionCommand, completionCommandConfig?.group);
|
|
1067
|
+
commandParsers.push(...ungroupedMeta);
|
|
1068
|
+
for (const [label, parsers] of Object.entries(groupedMeta)) commandParsers.push(require_constructs.group(label, parsers.length === 1 ? parsers[0] : require_constructs.longestMatch(...parsers)));
|
|
1069
|
+
const groupedMetaOptions = {};
|
|
1070
|
+
const ungroupedMetaOptions = [];
|
|
1071
|
+
const addMetaOption = (metaParser, groupLabel) => {
|
|
1072
|
+
if (groupLabel) (groupedMetaOptions[groupLabel] ??= []).push(metaParser);
|
|
1073
|
+
else ungroupedMetaOptions.push(metaParser);
|
|
1074
|
+
};
|
|
1075
|
+
if (helpAsOption && helpParsers.helpOption) addMetaOption(helpParsers.helpOption, helpOptionConfig?.group);
|
|
1076
|
+
if (versionAsOption && versionParsers.versionOption) addMetaOption(versionParsers.versionOption, versionOptionConfig?.group);
|
|
1077
|
+
if (completionAsOption && completionParsers.completionOption) addMetaOption(completionParsers.completionOption, completionOptionConfig?.group);
|
|
1078
|
+
commandParsers.push(...ungroupedMetaOptions);
|
|
1079
|
+
for (const [label, parsers] of Object.entries(groupedMetaOptions)) commandParsers.push(require_constructs.group(label, parsers.length === 1 ? parsers[0] : require_constructs.longestMatch(...parsers)));
|
|
1080
|
+
cachedRootHelpGeneratorParser = commandParsers.length === 1 ? commandParsers[0] : longestMatchForMetaCommands(...commandParsers);
|
|
1081
|
+
return cachedRootHelpGeneratorParser;
|
|
1082
|
+
};
|
|
1048
1083
|
const handleResult = (classified) => {
|
|
1049
1084
|
switch (classified.type) {
|
|
1050
1085
|
case "success": return classified.value;
|
|
@@ -1059,12 +1094,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1059
1094
|
case "help": {
|
|
1060
1095
|
let helpGeneratorParser;
|
|
1061
1096
|
let docGeneratorParser;
|
|
1062
|
-
const helpAsCommand = helpCommandConfig != null;
|
|
1063
|
-
const versionAsCommand = versionCommandConfig != null;
|
|
1064
|
-
const completionAsCommand = completionCommandConfig != null;
|
|
1065
|
-
const helpAsOption = helpOptionConfig != null;
|
|
1066
|
-
const versionAsOption = versionOptionConfig != null;
|
|
1067
|
-
const completionAsOption = completionOptionConfig != null;
|
|
1068
1097
|
const requestedCommand = classified.commands[0];
|
|
1069
1098
|
if (requestedCommand != null && !classified.preferUserCommandDocs && completionCommandNames.includes(requestedCommand) && completionAsCommand && completionParsers.completionCommand) {
|
|
1070
1099
|
helpGeneratorParser = completionParsers.completionCommand;
|
|
@@ -1076,33 +1105,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1076
1105
|
helpGeneratorParser = versionParsers.versionCommand;
|
|
1077
1106
|
docGeneratorParser = helpGeneratorParser;
|
|
1078
1107
|
} else {
|
|
1079
|
-
|
|
1080
|
-
const groupedMeta = {};
|
|
1081
|
-
const ungroupedMeta = [];
|
|
1082
|
-
const addMeta = (p, groupLabel) => {
|
|
1083
|
-
if (groupLabel) (groupedMeta[groupLabel] ??= []).push(p);
|
|
1084
|
-
else ungroupedMeta.push(p);
|
|
1085
|
-
};
|
|
1086
|
-
if (helpAsCommand && helpParsers.helpCommand) addMeta(helpParsers.helpCommand, helpCommandConfig?.group);
|
|
1087
|
-
if (versionAsCommand && versionParsers.versionCommand) addMeta(versionParsers.versionCommand, versionCommandConfig?.group);
|
|
1088
|
-
if (completionAsCommand && completionParsers.completionCommand) addMeta(completionParsers.completionCommand, completionCommandConfig?.group);
|
|
1089
|
-
commandParsers.push(...ungroupedMeta);
|
|
1090
|
-
for (const [label, parsers] of Object.entries(groupedMeta)) if (parsers.length === 1) commandParsers.push(require_constructs.group(label, parsers[0]));
|
|
1091
|
-
else commandParsers.push(require_constructs.group(label, require_constructs.longestMatch(...parsers)));
|
|
1092
|
-
const groupedMetaOptions = {};
|
|
1093
|
-
const ungroupedMetaOptions = [];
|
|
1094
|
-
const addMetaOption = (p, groupLabel) => {
|
|
1095
|
-
if (groupLabel) (groupedMetaOptions[groupLabel] ??= []).push(p);
|
|
1096
|
-
else ungroupedMetaOptions.push(p);
|
|
1097
|
-
};
|
|
1098
|
-
if (helpAsOption && helpParsers.helpOption) addMetaOption(helpParsers.helpOption, helpOptionConfig?.group);
|
|
1099
|
-
if (versionAsOption && versionParsers.versionOption) addMetaOption(versionParsers.versionOption, versionOptionConfig?.group);
|
|
1100
|
-
if (completionAsOption && completionParsers.completionOption) addMetaOption(completionParsers.completionOption, completionOptionConfig?.group);
|
|
1101
|
-
commandParsers.push(...ungroupedMetaOptions);
|
|
1102
|
-
for (const [label, optParsers] of Object.entries(groupedMetaOptions)) if (optParsers.length === 1) commandParsers.push(require_constructs.group(label, optParsers[0]));
|
|
1103
|
-
else commandParsers.push(require_constructs.group(label, require_constructs.longestMatch(...optParsers)));
|
|
1104
|
-
if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
|
|
1105
|
-
else helpGeneratorParser = longestMatchForMetaCommands(...commandParsers);
|
|
1108
|
+
helpGeneratorParser = getRootHelpGeneratorParser();
|
|
1106
1109
|
docGeneratorParser = classified.commands.length > 0 ? parser : helpGeneratorParser;
|
|
1107
1110
|
}
|
|
1108
1111
|
const reportInvalidHelpCommand = (validationError) => {
|
|
@@ -1133,7 +1136,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1133
1136
|
bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
|
|
1134
1137
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1135
1138
|
}, commandList, isTopLevel);
|
|
1136
|
-
|
|
1139
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine) : augmentedDoc;
|
|
1140
|
+
stdout(require_doc.formatDocPage(programName, renderedDoc, {
|
|
1137
1141
|
colors,
|
|
1138
1142
|
maxWidth,
|
|
1139
1143
|
showDefault,
|
|
@@ -1193,6 +1197,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1193
1197
|
let effectiveAboveError = currentAboveError;
|
|
1194
1198
|
if (effectiveAboveError === "help") if (doc == null) effectiveAboveError = "usage";
|
|
1195
1199
|
else {
|
|
1200
|
+
const isTopLevel = classified.commandPath.length < 1;
|
|
1196
1201
|
const augmentedDoc = maybeCollapseCommandList({
|
|
1197
1202
|
...doc,
|
|
1198
1203
|
brief: brief ?? doc.brief,
|
|
@@ -1201,8 +1206,10 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1201
1206
|
author: author ?? doc.author,
|
|
1202
1207
|
bugs: bugs ?? doc.bugs,
|
|
1203
1208
|
footer: footer ?? doc.footer
|
|
1204
|
-
}, commandList,
|
|
1205
|
-
|
|
1209
|
+
}, commandList, isTopLevel);
|
|
1210
|
+
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? require_usage.normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1211
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine, defaultRootUsage) : augmentedDoc;
|
|
1212
|
+
stderr(require_doc.formatDocPage(programName, renderedDoc, {
|
|
1206
1213
|
colors,
|
|
1207
1214
|
maxWidth,
|
|
1208
1215
|
showDefault,
|
|
@@ -1298,6 +1305,13 @@ function runParserAsync(parser, programName, args, options) {
|
|
|
1298
1305
|
const result = runParser(parser, programName, args, options);
|
|
1299
1306
|
return Promise.resolve(result);
|
|
1300
1307
|
}
|
|
1308
|
+
function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
1309
|
+
const customUsageLine = typeof usageLine === "function" ? usageLine(require_usage.cloneUsage(defaultUsageLine)) : usageLine;
|
|
1310
|
+
return {
|
|
1311
|
+
...doc,
|
|
1312
|
+
usage: require_usage.normalizeUsage(customUsageLine)
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1301
1315
|
function maybeCollapseCommandList(doc, commandList, isTopLevel) {
|
|
1302
1316
|
if (commandList !== "top-level" || !isTopLevel) return doc;
|
|
1303
1317
|
return {
|
package/dist/facade.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from "./message.cjs";
|
|
2
|
-
import { HiddenVisibility, OptionName } from "./usage.cjs";
|
|
2
|
+
import { HiddenVisibility, OptionName, Usage } from "./usage.cjs";
|
|
3
3
|
import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "./doc.cjs";
|
|
4
4
|
import { InferMode, InferValue, Mode, ModeValue, Parser } from "./internal/parser.cjs";
|
|
5
5
|
import { ShellCompletion } from "./completion.cjs";
|
|
@@ -127,6 +127,20 @@ interface RunOptions<THelp, TError> {
|
|
|
127
127
|
* @since 1.2.0
|
|
128
128
|
*/
|
|
129
129
|
readonly showUsage?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Usage line override for top-level full help.
|
|
132
|
+
*
|
|
133
|
+
* This option customizes the usage shown by `--help`, the root help command,
|
|
134
|
+
* and `aboveError: "help"` at the root. It does not affect subcommand help,
|
|
135
|
+
* parsing, shell completion, or usage-only error preambles from
|
|
136
|
+
* `aboveError: "usage"`.
|
|
137
|
+
*
|
|
138
|
+
* The callback form receives the generated root usage after built-in help,
|
|
139
|
+
* version, and completion entries have been added.
|
|
140
|
+
*
|
|
141
|
+
* @since 1.3.0
|
|
142
|
+
*/
|
|
143
|
+
readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
|
|
130
144
|
/**
|
|
131
145
|
* How to render command lists in top-level help pages.
|
|
132
146
|
*
|
package/dist/facade.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Message } from "./message.js";
|
|
2
|
-
import { HiddenVisibility, OptionName } from "./usage.js";
|
|
2
|
+
import { HiddenVisibility, OptionName, Usage } from "./usage.js";
|
|
3
3
|
import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "./doc.js";
|
|
4
4
|
import { InferMode, InferValue, Mode, ModeValue, Parser } from "./internal/parser.js";
|
|
5
5
|
import { ShellCompletion } from "./completion.js";
|
|
@@ -127,6 +127,20 @@ interface RunOptions<THelp, TError> {
|
|
|
127
127
|
* @since 1.2.0
|
|
128
128
|
*/
|
|
129
129
|
readonly showUsage?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Usage line override for top-level full help.
|
|
132
|
+
*
|
|
133
|
+
* This option customizes the usage shown by `--help`, the root help command,
|
|
134
|
+
* and `aboveError: "help"` at the root. It does not affect subcommand help,
|
|
135
|
+
* parsing, shell completion, or usage-only error preambles from
|
|
136
|
+
* `aboveError: "usage"`.
|
|
137
|
+
*
|
|
138
|
+
* The callback form receives the generated root usage after built-in help,
|
|
139
|
+
* version, and completion entries have been added.
|
|
140
|
+
*
|
|
141
|
+
* @since 1.3.0
|
|
142
|
+
*/
|
|
143
|
+
readonly usageLine?: Usage | ((defaultUsageLine: Usage) => Usage);
|
|
130
144
|
/**
|
|
131
145
|
* How to render command lists in top-level help pages.
|
|
132
146
|
*
|
package/dist/facade.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { injectAnnotations, isInjectedAnnotationWrapper, unwrapInjectedAnnotationWrapper } from "./internal/annotations.js";
|
|
2
2
|
import { commandLine, formatMessage, lineBreak, message, optionName, text, value } from "./message.js";
|
|
3
3
|
import { validateCommandNames, validateContextIds, validateMetaNameCollisions, validateOptionNames, validateProgramName } from "./validate.js";
|
|
4
|
-
import { formatUsage, isSuggestionHidden } from "./usage.js";
|
|
4
|
+
import { cloneUsage, formatUsage, isSuggestionHidden, normalizeUsage } from "./usage.js";
|
|
5
5
|
import { formatDocPage } from "./doc.js";
|
|
6
6
|
import { dispatchByMode } from "./internal/mode-dispatch.js";
|
|
7
7
|
import { collectExplicitSourceValues, collectExplicitSourceValuesAsync, createDependencyRuntimeContext } from "./dependency-runtime.js";
|
|
@@ -952,7 +952,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
952
952
|
options = optionsParam ?? {};
|
|
953
953
|
}
|
|
954
954
|
validateProgramName(programName);
|
|
955
|
-
const { colors, maxWidth, showDefault, showChoices, sectionOrder, showUsage, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
955
|
+
const { colors, maxWidth, showDefault, showChoices, sectionOrder, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
956
956
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
957
957
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
958
958
|
const norm = (c) => c === true ? {} : c;
|
|
@@ -1045,6 +1045,41 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1045
1045
|
completionCommandGroup: completionCommandConfig?.group,
|
|
1046
1046
|
completionOptionGroup: completionOptionConfig?.group
|
|
1047
1047
|
});
|
|
1048
|
+
const helpAsCommand = helpCommandConfig != null;
|
|
1049
|
+
const versionAsCommand = versionCommandConfig != null;
|
|
1050
|
+
const completionAsCommand = completionCommandConfig != null;
|
|
1051
|
+
const helpAsOption = helpOptionConfig != null;
|
|
1052
|
+
const versionAsOption = versionOptionConfig != null;
|
|
1053
|
+
const completionAsOption = completionOptionConfig != null;
|
|
1054
|
+
let cachedRootHelpGeneratorParser;
|
|
1055
|
+
const getRootHelpGeneratorParser = () => {
|
|
1056
|
+
if (cachedRootHelpGeneratorParser != null) return cachedRootHelpGeneratorParser;
|
|
1057
|
+
const commandParsers = [parser];
|
|
1058
|
+
const groupedMeta = {};
|
|
1059
|
+
const ungroupedMeta = [];
|
|
1060
|
+
const addMeta = (metaParser, groupLabel) => {
|
|
1061
|
+
if (groupLabel) (groupedMeta[groupLabel] ??= []).push(metaParser);
|
|
1062
|
+
else ungroupedMeta.push(metaParser);
|
|
1063
|
+
};
|
|
1064
|
+
if (helpAsCommand && helpParsers.helpCommand) addMeta(helpParsers.helpCommand, helpCommandConfig?.group);
|
|
1065
|
+
if (versionAsCommand && versionParsers.versionCommand) addMeta(versionParsers.versionCommand, versionCommandConfig?.group);
|
|
1066
|
+
if (completionAsCommand && completionParsers.completionCommand) addMeta(completionParsers.completionCommand, completionCommandConfig?.group);
|
|
1067
|
+
commandParsers.push(...ungroupedMeta);
|
|
1068
|
+
for (const [label, parsers] of Object.entries(groupedMeta)) commandParsers.push(group(label, parsers.length === 1 ? parsers[0] : longestMatch(...parsers)));
|
|
1069
|
+
const groupedMetaOptions = {};
|
|
1070
|
+
const ungroupedMetaOptions = [];
|
|
1071
|
+
const addMetaOption = (metaParser, groupLabel) => {
|
|
1072
|
+
if (groupLabel) (groupedMetaOptions[groupLabel] ??= []).push(metaParser);
|
|
1073
|
+
else ungroupedMetaOptions.push(metaParser);
|
|
1074
|
+
};
|
|
1075
|
+
if (helpAsOption && helpParsers.helpOption) addMetaOption(helpParsers.helpOption, helpOptionConfig?.group);
|
|
1076
|
+
if (versionAsOption && versionParsers.versionOption) addMetaOption(versionParsers.versionOption, versionOptionConfig?.group);
|
|
1077
|
+
if (completionAsOption && completionParsers.completionOption) addMetaOption(completionParsers.completionOption, completionOptionConfig?.group);
|
|
1078
|
+
commandParsers.push(...ungroupedMetaOptions);
|
|
1079
|
+
for (const [label, parsers] of Object.entries(groupedMetaOptions)) commandParsers.push(group(label, parsers.length === 1 ? parsers[0] : longestMatch(...parsers)));
|
|
1080
|
+
cachedRootHelpGeneratorParser = commandParsers.length === 1 ? commandParsers[0] : longestMatchForMetaCommands(...commandParsers);
|
|
1081
|
+
return cachedRootHelpGeneratorParser;
|
|
1082
|
+
};
|
|
1048
1083
|
const handleResult = (classified) => {
|
|
1049
1084
|
switch (classified.type) {
|
|
1050
1085
|
case "success": return classified.value;
|
|
@@ -1059,12 +1094,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1059
1094
|
case "help": {
|
|
1060
1095
|
let helpGeneratorParser;
|
|
1061
1096
|
let docGeneratorParser;
|
|
1062
|
-
const helpAsCommand = helpCommandConfig != null;
|
|
1063
|
-
const versionAsCommand = versionCommandConfig != null;
|
|
1064
|
-
const completionAsCommand = completionCommandConfig != null;
|
|
1065
|
-
const helpAsOption = helpOptionConfig != null;
|
|
1066
|
-
const versionAsOption = versionOptionConfig != null;
|
|
1067
|
-
const completionAsOption = completionOptionConfig != null;
|
|
1068
1097
|
const requestedCommand = classified.commands[0];
|
|
1069
1098
|
if (requestedCommand != null && !classified.preferUserCommandDocs && completionCommandNames.includes(requestedCommand) && completionAsCommand && completionParsers.completionCommand) {
|
|
1070
1099
|
helpGeneratorParser = completionParsers.completionCommand;
|
|
@@ -1076,33 +1105,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1076
1105
|
helpGeneratorParser = versionParsers.versionCommand;
|
|
1077
1106
|
docGeneratorParser = helpGeneratorParser;
|
|
1078
1107
|
} else {
|
|
1079
|
-
|
|
1080
|
-
const groupedMeta = {};
|
|
1081
|
-
const ungroupedMeta = [];
|
|
1082
|
-
const addMeta = (p, groupLabel) => {
|
|
1083
|
-
if (groupLabel) (groupedMeta[groupLabel] ??= []).push(p);
|
|
1084
|
-
else ungroupedMeta.push(p);
|
|
1085
|
-
};
|
|
1086
|
-
if (helpAsCommand && helpParsers.helpCommand) addMeta(helpParsers.helpCommand, helpCommandConfig?.group);
|
|
1087
|
-
if (versionAsCommand && versionParsers.versionCommand) addMeta(versionParsers.versionCommand, versionCommandConfig?.group);
|
|
1088
|
-
if (completionAsCommand && completionParsers.completionCommand) addMeta(completionParsers.completionCommand, completionCommandConfig?.group);
|
|
1089
|
-
commandParsers.push(...ungroupedMeta);
|
|
1090
|
-
for (const [label, parsers] of Object.entries(groupedMeta)) if (parsers.length === 1) commandParsers.push(group(label, parsers[0]));
|
|
1091
|
-
else commandParsers.push(group(label, longestMatch(...parsers)));
|
|
1092
|
-
const groupedMetaOptions = {};
|
|
1093
|
-
const ungroupedMetaOptions = [];
|
|
1094
|
-
const addMetaOption = (p, groupLabel) => {
|
|
1095
|
-
if (groupLabel) (groupedMetaOptions[groupLabel] ??= []).push(p);
|
|
1096
|
-
else ungroupedMetaOptions.push(p);
|
|
1097
|
-
};
|
|
1098
|
-
if (helpAsOption && helpParsers.helpOption) addMetaOption(helpParsers.helpOption, helpOptionConfig?.group);
|
|
1099
|
-
if (versionAsOption && versionParsers.versionOption) addMetaOption(versionParsers.versionOption, versionOptionConfig?.group);
|
|
1100
|
-
if (completionAsOption && completionParsers.completionOption) addMetaOption(completionParsers.completionOption, completionOptionConfig?.group);
|
|
1101
|
-
commandParsers.push(...ungroupedMetaOptions);
|
|
1102
|
-
for (const [label, optParsers] of Object.entries(groupedMetaOptions)) if (optParsers.length === 1) commandParsers.push(group(label, optParsers[0]));
|
|
1103
|
-
else commandParsers.push(group(label, longestMatch(...optParsers)));
|
|
1104
|
-
if (commandParsers.length === 1) helpGeneratorParser = commandParsers[0];
|
|
1105
|
-
else helpGeneratorParser = longestMatchForMetaCommands(...commandParsers);
|
|
1108
|
+
helpGeneratorParser = getRootHelpGeneratorParser();
|
|
1106
1109
|
docGeneratorParser = classified.commands.length > 0 ? parser : helpGeneratorParser;
|
|
1107
1110
|
}
|
|
1108
1111
|
const reportInvalidHelpCommand = (validationError) => {
|
|
@@ -1133,7 +1136,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1133
1136
|
bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
|
|
1134
1137
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1135
1138
|
}, commandList, isTopLevel);
|
|
1136
|
-
|
|
1139
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine) : augmentedDoc;
|
|
1140
|
+
stdout(formatDocPage(programName, renderedDoc, {
|
|
1137
1141
|
colors,
|
|
1138
1142
|
maxWidth,
|
|
1139
1143
|
showDefault,
|
|
@@ -1193,6 +1197,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1193
1197
|
let effectiveAboveError = currentAboveError;
|
|
1194
1198
|
if (effectiveAboveError === "help") if (doc == null) effectiveAboveError = "usage";
|
|
1195
1199
|
else {
|
|
1200
|
+
const isTopLevel = classified.commandPath.length < 1;
|
|
1196
1201
|
const augmentedDoc = maybeCollapseCommandList({
|
|
1197
1202
|
...doc,
|
|
1198
1203
|
brief: brief ?? doc.brief,
|
|
@@ -1201,8 +1206,10 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1201
1206
|
author: author ?? doc.author,
|
|
1202
1207
|
bugs: bugs ?? doc.bugs,
|
|
1203
1208
|
footer: footer ?? doc.footer
|
|
1204
|
-
}, commandList,
|
|
1205
|
-
|
|
1209
|
+
}, commandList, isTopLevel);
|
|
1210
|
+
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1211
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(augmentedDoc, usageLine, defaultRootUsage) : augmentedDoc;
|
|
1212
|
+
stderr(formatDocPage(programName, renderedDoc, {
|
|
1206
1213
|
colors,
|
|
1207
1214
|
maxWidth,
|
|
1208
1215
|
showDefault,
|
|
@@ -1298,6 +1305,13 @@ function runParserAsync(parser, programName, args, options) {
|
|
|
1298
1305
|
const result = runParser(parser, programName, args, options);
|
|
1299
1306
|
return Promise.resolve(result);
|
|
1300
1307
|
}
|
|
1308
|
+
function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
1309
|
+
const customUsageLine = typeof usageLine === "function" ? usageLine(cloneUsage(defaultUsageLine)) : usageLine;
|
|
1310
|
+
return {
|
|
1311
|
+
...doc,
|
|
1312
|
+
usage: normalizeUsage(customUsageLine)
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1301
1315
|
function maybeCollapseCommandList(doc, commandList, isTopLevel) {
|
|
1302
1316
|
if (commandList !== "top-level" || !isTopLevel) return doc;
|
|
1303
1317
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.3.0-dev.
|
|
3
|
+
"version": "1.3.0-dev.2353",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -225,7 +225,7 @@
|
|
|
225
225
|
"fast-check": "^4.7.0",
|
|
226
226
|
"tsdown": "^0.13.0",
|
|
227
227
|
"typescript": "^5.8.3",
|
|
228
|
-
"@optique/env": "1.3.0-dev.
|
|
228
|
+
"@optique/env": "1.3.0-dev.2353+1e07f6ab"
|
|
229
229
|
},
|
|
230
230
|
"scripts": {
|
|
231
231
|
"build": "tsdown",
|
package/skills/optique/SKILL.md
CHANGED
|
@@ -56,6 +56,9 @@ Core rules
|
|
|
56
56
|
discriminated union.
|
|
57
57
|
- Enable completion through `run(parser, { completion: "both" })` for CLI
|
|
58
58
|
apps. Do not hand-write completion scripts from parser metadata.
|
|
59
|
+
- Use `usageLine: [{ type: "ellipsis" }]` in runner options when a large root
|
|
60
|
+
synopsis should become a compact `Usage: myapp ...` line. This applies only
|
|
61
|
+
to root full help; use `command()`'s `usageLine` for subcommand help.
|
|
59
62
|
- Use `showUsage: false` in runner options when full help should show the
|
|
60
63
|
brief and command or option sections without the `Usage:` synopsis.
|
|
61
64
|
For deeply nested command trees, add `commandList: "top-level"` when root
|