@optique/core 1.4.0-dev.2619 → 1.4.0-dev.2623
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 +71 -3
- package/dist/facade.d.cts +32 -2
- package/dist/facade.d.ts +32 -2
- package/dist/facade.js +74 -6
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/package.json +2 -2
- package/skills/optique/SKILL.md +14 -14
package/dist/facade.cjs
CHANGED
|
@@ -818,7 +818,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
818
818
|
options = optionsParam ?? {};
|
|
819
819
|
}
|
|
820
820
|
require_validate.validateProgramName(programName);
|
|
821
|
-
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
821
|
+
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder, helpSections, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
822
822
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
823
823
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
824
824
|
let maxWidth = requestedMaxWidth;
|
|
@@ -850,6 +850,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
850
850
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
851
851
|
const onCompletionResult = (code) => onCompletion(code);
|
|
852
852
|
const onErrorResult = (code, error) => onError(code, error);
|
|
853
|
+
for (const label of [helpSections?.commands, helpSections?.options]) if (label !== void 0) require_validate.validateLabel(label);
|
|
853
854
|
if (helpOptionConfig?.names) require_validate.validateOptionNames(helpOptionConfig.names, "Help option");
|
|
854
855
|
if (helpCommandConfig?.names) require_validate.validateCommandNames(helpCommandConfig.names, "Help command");
|
|
855
856
|
if (versionOptionConfig?.names) require_validate.validateOptionNames(versionOptionConfig.names, "Version option");
|
|
@@ -1022,7 +1023,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1022
1023
|
bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
|
|
1023
1024
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1024
1025
|
}, commandList, isTopLevel);
|
|
1025
|
-
const
|
|
1026
|
+
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1027
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc;
|
|
1026
1028
|
stdout(require_doc.formatDocPage(programName, renderedDoc, formatOptions({
|
|
1027
1029
|
messageFormatter,
|
|
1028
1030
|
theme,
|
|
@@ -1098,7 +1100,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1098
1100
|
footer: footer ?? doc.footer
|
|
1099
1101
|
}, commandList, isTopLevel);
|
|
1100
1102
|
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? require_usage.normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1101
|
-
const
|
|
1103
|
+
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1104
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc;
|
|
1102
1105
|
stderr(require_doc.formatDocPage(programName, renderedDoc, formatOptions({
|
|
1103
1106
|
messageFormatter,
|
|
1104
1107
|
theme,
|
|
@@ -1185,6 +1188,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1185
1188
|
* @returns The parsed result if successful.
|
|
1186
1189
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
1187
1190
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
1191
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1188
1192
|
* @since 0.9.0
|
|
1189
1193
|
*/
|
|
1190
1194
|
function runParserSync(parser, programName, args, options) {
|
|
@@ -1207,6 +1211,7 @@ function runParserSync(parser, programName, args, options) {
|
|
|
1207
1211
|
* @param options Configuration options for customizing behavior.
|
|
1208
1212
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1209
1213
|
* color, even when colors are disabled.
|
|
1214
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1210
1215
|
* @returns A Promise of the parsed result if successful.
|
|
1211
1216
|
* @since 0.9.0
|
|
1212
1217
|
*/
|
|
@@ -1221,6 +1226,66 @@ function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
|
1221
1226
|
usage: require_usage.normalizeUsage(customUsageLine)
|
|
1222
1227
|
};
|
|
1223
1228
|
}
|
|
1229
|
+
/** Prepares the runner's final page without changing parser documentation. */
|
|
1230
|
+
function applyHelpSections(doc, labels) {
|
|
1231
|
+
if (labels == null || labels.commands == null && labels.options == null) return doc;
|
|
1232
|
+
const visible = (entry) => !require_doc.isDocEntryHidden(entry) && require_usage.formatUsageTerm(entry.term, { context: "doc" }).trim() !== "";
|
|
1233
|
+
if (!doc.sections.some((section) => section.entries.some((entry) => entry.term.type === "command" && visible(entry)))) return doc;
|
|
1234
|
+
const existingTitles = new Set(doc.sections.flatMap((section) => section.title == null ? [] : [section.title]));
|
|
1235
|
+
const additions = /* @__PURE__ */ new Map();
|
|
1236
|
+
const residuals = /* @__PURE__ */ new Map();
|
|
1237
|
+
const newSections = /* @__PURE__ */ new Map();
|
|
1238
|
+
for (const section of doc.sections) {
|
|
1239
|
+
if (section.title != null) continue;
|
|
1240
|
+
const commands = [];
|
|
1241
|
+
const options = [];
|
|
1242
|
+
const remaining = [];
|
|
1243
|
+
for (const entry of section.entries) if (entry.term.type === "command" && labels.commands != null && visible(entry)) commands.push(entry);
|
|
1244
|
+
else if (entry.term.type === "option" && labels.options != null && visible(entry)) options.push(entry);
|
|
1245
|
+
else remaining.push(entry);
|
|
1246
|
+
if (commands.length === 0 && options.length === 0) continue;
|
|
1247
|
+
residuals.set(section, remaining);
|
|
1248
|
+
for (const [label, entries] of [[labels.commands, commands], [labels.options, options]]) {
|
|
1249
|
+
if (label == null || entries.length === 0) continue;
|
|
1250
|
+
const previous = additions.get(label);
|
|
1251
|
+
if (previous != null) previous.push(...entries);
|
|
1252
|
+
else {
|
|
1253
|
+
additions.set(label, entries);
|
|
1254
|
+
if (!existingTitles.has(label)) {
|
|
1255
|
+
const titles = newSections.get(section) ?? [];
|
|
1256
|
+
titles.push(label);
|
|
1257
|
+
newSections.set(section, titles);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
if (additions.size === 0) return doc;
|
|
1263
|
+
const sections = [];
|
|
1264
|
+
for (const section of doc.sections) {
|
|
1265
|
+
if (section.title != null) {
|
|
1266
|
+
const entries$1 = additions.get(section.title);
|
|
1267
|
+
sections.push(entries$1 == null ? section : {
|
|
1268
|
+
...section,
|
|
1269
|
+
entries: [...section.entries, ...entries$1]
|
|
1270
|
+
});
|
|
1271
|
+
continue;
|
|
1272
|
+
}
|
|
1273
|
+
for (const title of newSections.get(section) ?? []) sections.push({
|
|
1274
|
+
title,
|
|
1275
|
+
entries: additions.get(title) ?? []
|
|
1276
|
+
});
|
|
1277
|
+
const entries = residuals.get(section);
|
|
1278
|
+
if (entries == null) sections.push(section);
|
|
1279
|
+
else if (entries.length > 0) sections.push({
|
|
1280
|
+
...section,
|
|
1281
|
+
entries
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
return {
|
|
1285
|
+
...doc,
|
|
1286
|
+
sections
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1224
1289
|
function maybeCollapseCommandList(doc, commandList, isTopLevel) {
|
|
1225
1290
|
if (commandList !== "top-level" || !isTopLevel) return doc;
|
|
1226
1291
|
return {
|
|
@@ -1556,6 +1621,7 @@ async function runWithBody(parser, programName, contexts, args, options) {
|
|
|
1556
1621
|
* @param programName Name of the program for help/error output.
|
|
1557
1622
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1558
1623
|
* @param options Run options including args, help, version, etc.
|
|
1624
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1559
1625
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1560
1626
|
* color, even when colors are disabled.
|
|
1561
1627
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -1656,6 +1722,7 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
|
|
|
1656
1722
|
* @param programName Name of the program for help/error output.
|
|
1657
1723
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1658
1724
|
* @param options Run options including args, help, version, etc.
|
|
1725
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1659
1726
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1660
1727
|
* color, even when colors are disabled.
|
|
1661
1728
|
* @returns The parsed result.
|
|
@@ -1707,6 +1774,7 @@ function runWithSync(parser, programName, contexts, options) {
|
|
|
1707
1774
|
* @param programName Name of the program for help/error output.
|
|
1708
1775
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1709
1776
|
* @param options Run options including args, help, version, etc.
|
|
1777
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1710
1778
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1711
1779
|
* color, even when colors are disabled.
|
|
1712
1780
|
* @returns Promise that resolves to the parsed result.
|
package/dist/facade.d.cts
CHANGED
|
@@ -20,6 +20,19 @@ 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
|
+
}
|
|
23
36
|
/**
|
|
24
37
|
* Sub-configuration for a meta command's command form.
|
|
25
38
|
*
|
|
@@ -184,6 +197,16 @@ interface RunOptions<THelp, TError> {
|
|
|
184
197
|
* @since 1.0.0
|
|
185
198
|
*/
|
|
186
199
|
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;
|
|
187
210
|
/**
|
|
188
211
|
* Help configuration. When provided, enables help functionality.
|
|
189
212
|
* At least one of `command` or `option` must be specified.
|
|
@@ -382,7 +405,9 @@ interface RunOptions<THelp, TError> {
|
|
|
382
405
|
* non-empty string without ASCII control characters, or if any
|
|
383
406
|
* meta command/option name is empty, whitespace-only, contains
|
|
384
407
|
* whitespace or control characters, or (for option names) lacks a
|
|
385
|
-
* valid prefix (`--`, `-`, `/`, or `+`).
|
|
408
|
+
* valid prefix (`--`, `-`, `/`, or `+`). Also thrown if a
|
|
409
|
+
* `helpSections` label is empty, whitespace-only, or contains
|
|
410
|
+
* control characters.
|
|
386
411
|
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
387
412
|
* provided, or if the requested help page cannot be generated.
|
|
388
413
|
* @since 0.10.0 Added support for {@link Program} objects.
|
|
@@ -411,6 +436,7 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
|
|
|
411
436
|
* @returns The parsed result if successful.
|
|
412
437
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
413
438
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
439
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
414
440
|
* @since 0.9.0
|
|
415
441
|
*/
|
|
416
442
|
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>;
|
|
@@ -430,6 +456,7 @@ declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>,
|
|
|
430
456
|
* @param options Configuration options for customizing behavior.
|
|
431
457
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
432
458
|
* color, even when colors are disabled.
|
|
459
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
433
460
|
* @returns A Promise of the parsed result if successful.
|
|
434
461
|
* @since 0.9.0
|
|
435
462
|
*/
|
|
@@ -544,6 +571,7 @@ type ContextOptionsParam<TContexts extends readonly SourceContext<unknown>[], TV
|
|
|
544
571
|
* @param programName Name of the program for help/error output.
|
|
545
572
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
546
573
|
* @param options Run options including args, help, version, etc.
|
|
574
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
547
575
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
548
576
|
* color, even when colors are disabled.
|
|
549
577
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -595,6 +623,7 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
|
|
|
595
623
|
* @param programName Name of the program for help/error output.
|
|
596
624
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
597
625
|
* @param options Run options including args, help, version, etc.
|
|
626
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
598
627
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
599
628
|
* color, even when colors are disabled.
|
|
600
629
|
* @returns The parsed result.
|
|
@@ -625,6 +654,7 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
625
654
|
* @param programName Name of the program for help/error output.
|
|
626
655
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
627
656
|
* @param options Run options including args, help, version, etc.
|
|
657
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
628
658
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
629
659
|
* color, even when colors are disabled.
|
|
630
660
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -637,4 +667,4 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
637
667
|
*/
|
|
638
668
|
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>>;
|
|
639
669
|
//#endregion
|
|
640
|
-
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, type SourceContextRequest, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
|
670
|
+
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, HelpSectionsOptions, OptionSubConfig, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, type SourceContextRequest, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
package/dist/facade.d.ts
CHANGED
|
@@ -20,6 +20,19 @@ 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
|
+
}
|
|
23
36
|
/**
|
|
24
37
|
* Sub-configuration for a meta command's command form.
|
|
25
38
|
*
|
|
@@ -184,6 +197,16 @@ interface RunOptions<THelp, TError> {
|
|
|
184
197
|
* @since 1.0.0
|
|
185
198
|
*/
|
|
186
199
|
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;
|
|
187
210
|
/**
|
|
188
211
|
* Help configuration. When provided, enables help functionality.
|
|
189
212
|
* At least one of `command` or `option` must be specified.
|
|
@@ -382,7 +405,9 @@ interface RunOptions<THelp, TError> {
|
|
|
382
405
|
* non-empty string without ASCII control characters, or if any
|
|
383
406
|
* meta command/option name is empty, whitespace-only, contains
|
|
384
407
|
* whitespace or control characters, or (for option names) lacks a
|
|
385
|
-
* valid prefix (`--`, `-`, `/`, or `+`).
|
|
408
|
+
* valid prefix (`--`, `-`, `/`, or `+`). Also thrown if a
|
|
409
|
+
* `helpSections` label is empty, whitespace-only, or contains
|
|
410
|
+
* control characters.
|
|
386
411
|
* @throws {RunParserError} When parsing fails and no `onError` callback is
|
|
387
412
|
* provided, or if the requested help page cannot be generated.
|
|
388
413
|
* @since 0.10.0 Added support for {@link Program} objects.
|
|
@@ -411,6 +436,7 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
|
|
|
411
436
|
* @returns The parsed result if successful.
|
|
412
437
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
413
438
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
439
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
414
440
|
* @since 0.9.0
|
|
415
441
|
*/
|
|
416
442
|
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>;
|
|
@@ -430,6 +456,7 @@ declare function runParserSync<TParser extends Parser<"sync", unknown, unknown>,
|
|
|
430
456
|
* @param options Configuration options for customizing behavior.
|
|
431
457
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
432
458
|
* color, even when colors are disabled.
|
|
459
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
433
460
|
* @returns A Promise of the parsed result if successful.
|
|
434
461
|
* @since 0.9.0
|
|
435
462
|
*/
|
|
@@ -544,6 +571,7 @@ type ContextOptionsParam<TContexts extends readonly SourceContext<unknown>[], TV
|
|
|
544
571
|
* @param programName Name of the program for help/error output.
|
|
545
572
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
546
573
|
* @param options Run options including args, help, version, etc.
|
|
574
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
547
575
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
548
576
|
* color, even when colors are disabled.
|
|
549
577
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -595,6 +623,7 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
|
|
|
595
623
|
* @param programName Name of the program for help/error output.
|
|
596
624
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
597
625
|
* @param options Run options including args, help, version, etc.
|
|
626
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
598
627
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
599
628
|
* color, even when colors are disabled.
|
|
600
629
|
* @returns The parsed result.
|
|
@@ -625,6 +654,7 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
625
654
|
* @param programName Name of the program for help/error output.
|
|
626
655
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
627
656
|
* @param options Run options including args, help, version, etc.
|
|
657
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
628
658
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
629
659
|
* color, even when colors are disabled.
|
|
630
660
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -637,4 +667,4 @@ declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, T
|
|
|
637
667
|
*/
|
|
638
668
|
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>>;
|
|
639
669
|
//#endregion
|
|
640
|
-
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, type SourceContextRequest, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
|
670
|
+
export { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, HelpSectionsOptions, OptionSubConfig, type ParserValuePlaceholder, RunOptions, RunParserError, RunWithOptions, type SourceContext, type SourceContextRequest, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync };
|
package/dist/facade.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { injectAnnotations } from "./internal/annotations.js";
|
|
2
2
|
import { cacheTerminalTheme, renderTerminalTerm } from "./terminal-internal.js";
|
|
3
3
|
import { measureText, spaceAfterLabel } from "./text-layout.js";
|
|
4
|
-
import { validateCommandNames, validateContextIds, validateMetaNameCollisions, validateOptionNames, validateProgramName } from "./validate.js";
|
|
5
|
-
import { cloneUsage, formatUsage, isSuggestionHidden, normalizeUsage } from "./usage.js";
|
|
4
|
+
import { validateCommandNames, validateContextIds, validateLabel, validateMetaNameCollisions, validateOptionNames, validateProgramName } from "./validate.js";
|
|
5
|
+
import { cloneUsage, formatUsage, formatUsageTerm, isSuggestionHidden, normalizeUsage } from "./usage.js";
|
|
6
6
|
import { hasAutomaticWidth, minimumUsageWidth, withAutomaticWidth } from "./terminal-width.js";
|
|
7
7
|
import { commandLine, lineBreak, message, optionName, text, value } from "./message.js";
|
|
8
8
|
import { renderErrorMessage } from "./message-renderer.js";
|
|
9
|
-
import { formatDocPage } from "./doc.js";
|
|
9
|
+
import { formatDocPage, isDocEntryHidden } from "./doc.js";
|
|
10
10
|
import { dispatchByMode } from "./internal/mode-dispatch.js";
|
|
11
11
|
import { collectExplicitSourceValues, collectExplicitSourceValuesAsync, createDependencyRuntimeContext } from "./dependency-runtime.js";
|
|
12
12
|
import { createInputTrace } from "./input-trace.js";
|
|
@@ -818,7 +818,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
818
818
|
options = optionsParam ?? {};
|
|
819
819
|
}
|
|
820
820
|
validateProgramName(programName);
|
|
821
|
-
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
821
|
+
const { colors, messageFormatter, theme: requestedTheme, maxWidth: requestedMaxWidth, termWidth, showDefault, showChoices, sectionOrder, helpSections, showUsage, usageLine, commandList = "recursive", aboveError = "usage", onError = () => {
|
|
822
822
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
823
823
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
824
824
|
let maxWidth = requestedMaxWidth;
|
|
@@ -850,6 +850,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
850
850
|
const onCompletion = options.completion?.onShow ?? (() => ({}));
|
|
851
851
|
const onCompletionResult = (code) => onCompletion(code);
|
|
852
852
|
const onErrorResult = (code, error) => onError(code, error);
|
|
853
|
+
for (const label of [helpSections?.commands, helpSections?.options]) if (label !== void 0) validateLabel(label);
|
|
853
854
|
if (helpOptionConfig?.names) validateOptionNames(helpOptionConfig.names, "Help option");
|
|
854
855
|
if (helpCommandConfig?.names) validateCommandNames(helpCommandConfig.names, "Help command");
|
|
855
856
|
if (versionOptionConfig?.names) validateOptionNames(versionOptionConfig.names, "Version option");
|
|
@@ -1022,7 +1023,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1022
1023
|
bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
|
|
1023
1024
|
footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
|
|
1024
1025
|
}, commandList, isTopLevel);
|
|
1025
|
-
const
|
|
1026
|
+
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1027
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine) : groupedDoc;
|
|
1026
1028
|
stdout(formatDocPage(programName, renderedDoc, formatOptions({
|
|
1027
1029
|
messageFormatter,
|
|
1028
1030
|
theme,
|
|
@@ -1098,7 +1100,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1098
1100
|
footer: footer ?? doc.footer
|
|
1099
1101
|
}, commandList, isTopLevel);
|
|
1100
1102
|
const defaultRootUsage = typeof usageLine === "function" && (options.help || options.version || options.completion) ? normalizeUsage(getRootHelpGeneratorParser().usage) : augmentedDoc.usage ?? [];
|
|
1101
|
-
const
|
|
1103
|
+
const groupedDoc = applyHelpSections(augmentedDoc, helpSections);
|
|
1104
|
+
const renderedDoc = isTopLevel && usageLine != null ? applyUsageLine(groupedDoc, usageLine, defaultRootUsage) : groupedDoc;
|
|
1102
1105
|
stderr(formatDocPage(programName, renderedDoc, formatOptions({
|
|
1103
1106
|
messageFormatter,
|
|
1104
1107
|
theme,
|
|
@@ -1185,6 +1188,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1185
1188
|
* @returns The parsed result if successful.
|
|
1186
1189
|
* @throws {TypeError} If an async parser is passed at runtime. Use
|
|
1187
1190
|
* {@link runParser} or {@link runParserAsync} for async parsers.
|
|
1191
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1188
1192
|
* @since 0.9.0
|
|
1189
1193
|
*/
|
|
1190
1194
|
function runParserSync(parser, programName, args, options) {
|
|
@@ -1207,6 +1211,7 @@ function runParserSync(parser, programName, args, options) {
|
|
|
1207
1211
|
* @param options Configuration options for customizing behavior.
|
|
1208
1212
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1209
1213
|
* color, even when colors are disabled.
|
|
1214
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1210
1215
|
* @returns A Promise of the parsed result if successful.
|
|
1211
1216
|
* @since 0.9.0
|
|
1212
1217
|
*/
|
|
@@ -1221,6 +1226,66 @@ function applyUsageLine(doc, usageLine, defaultUsageLine = doc.usage ?? []) {
|
|
|
1221
1226
|
usage: normalizeUsage(customUsageLine)
|
|
1222
1227
|
};
|
|
1223
1228
|
}
|
|
1229
|
+
/** Prepares the runner's final page without changing parser documentation. */
|
|
1230
|
+
function applyHelpSections(doc, labels) {
|
|
1231
|
+
if (labels == null || labels.commands == null && labels.options == null) return doc;
|
|
1232
|
+
const visible = (entry) => !isDocEntryHidden(entry) && formatUsageTerm(entry.term, { context: "doc" }).trim() !== "";
|
|
1233
|
+
if (!doc.sections.some((section) => section.entries.some((entry) => entry.term.type === "command" && visible(entry)))) return doc;
|
|
1234
|
+
const existingTitles = new Set(doc.sections.flatMap((section) => section.title == null ? [] : [section.title]));
|
|
1235
|
+
const additions = /* @__PURE__ */ new Map();
|
|
1236
|
+
const residuals = /* @__PURE__ */ new Map();
|
|
1237
|
+
const newSections = /* @__PURE__ */ new Map();
|
|
1238
|
+
for (const section of doc.sections) {
|
|
1239
|
+
if (section.title != null) continue;
|
|
1240
|
+
const commands = [];
|
|
1241
|
+
const options = [];
|
|
1242
|
+
const remaining = [];
|
|
1243
|
+
for (const entry of section.entries) if (entry.term.type === "command" && labels.commands != null && visible(entry)) commands.push(entry);
|
|
1244
|
+
else if (entry.term.type === "option" && labels.options != null && visible(entry)) options.push(entry);
|
|
1245
|
+
else remaining.push(entry);
|
|
1246
|
+
if (commands.length === 0 && options.length === 0) continue;
|
|
1247
|
+
residuals.set(section, remaining);
|
|
1248
|
+
for (const [label, entries] of [[labels.commands, commands], [labels.options, options]]) {
|
|
1249
|
+
if (label == null || entries.length === 0) continue;
|
|
1250
|
+
const previous = additions.get(label);
|
|
1251
|
+
if (previous != null) previous.push(...entries);
|
|
1252
|
+
else {
|
|
1253
|
+
additions.set(label, entries);
|
|
1254
|
+
if (!existingTitles.has(label)) {
|
|
1255
|
+
const titles = newSections.get(section) ?? [];
|
|
1256
|
+
titles.push(label);
|
|
1257
|
+
newSections.set(section, titles);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
if (additions.size === 0) return doc;
|
|
1263
|
+
const sections = [];
|
|
1264
|
+
for (const section of doc.sections) {
|
|
1265
|
+
if (section.title != null) {
|
|
1266
|
+
const entries$1 = additions.get(section.title);
|
|
1267
|
+
sections.push(entries$1 == null ? section : {
|
|
1268
|
+
...section,
|
|
1269
|
+
entries: [...section.entries, ...entries$1]
|
|
1270
|
+
});
|
|
1271
|
+
continue;
|
|
1272
|
+
}
|
|
1273
|
+
for (const title of newSections.get(section) ?? []) sections.push({
|
|
1274
|
+
title,
|
|
1275
|
+
entries: additions.get(title) ?? []
|
|
1276
|
+
});
|
|
1277
|
+
const entries = residuals.get(section);
|
|
1278
|
+
if (entries == null) sections.push(section);
|
|
1279
|
+
else if (entries.length > 0) sections.push({
|
|
1280
|
+
...section,
|
|
1281
|
+
entries
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
return {
|
|
1285
|
+
...doc,
|
|
1286
|
+
sections
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1224
1289
|
function maybeCollapseCommandList(doc, commandList, isTopLevel) {
|
|
1225
1290
|
if (commandList !== "top-level" || !isTopLevel) return doc;
|
|
1226
1291
|
return {
|
|
@@ -1556,6 +1621,7 @@ async function runWithBody(parser, programName, contexts, args, options) {
|
|
|
1556
1621
|
* @param programName Name of the program for help/error output.
|
|
1557
1622
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1558
1623
|
* @param options Run options including args, help, version, etc.
|
|
1624
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1559
1625
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1560
1626
|
* color, even when colors are disabled.
|
|
1561
1627
|
* @returns Promise that resolves to the parsed result.
|
|
@@ -1656,6 +1722,7 @@ function runWithSyncBody(parser, programName, contexts, args, options) {
|
|
|
1656
1722
|
* @param programName Name of the program for help/error output.
|
|
1657
1723
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1658
1724
|
* @param options Run options including args, help, version, etc.
|
|
1725
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1659
1726
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1660
1727
|
* color, even when colors are disabled.
|
|
1661
1728
|
* @returns The parsed result.
|
|
@@ -1707,6 +1774,7 @@ function runWithSync(parser, programName, contexts, options) {
|
|
|
1707
1774
|
* @param programName Name of the program for help/error output.
|
|
1708
1775
|
* @param contexts Source contexts to use (priority: earlier overrides later).
|
|
1709
1776
|
* @param options Run options including args, help, version, etc.
|
|
1777
|
+
* @throws {TypeError} If a `helpSections` label is invalid.
|
|
1710
1778
|
* @throws {RangeError} If rendering help or errors encounters an invalid theme
|
|
1711
1779
|
* color, even when colors are disabled.
|
|
1712
1780
|
* @returns Promise that resolves to the parsed result.
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,6 @@ import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser,
|
|
|
11
11
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, SeqOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.cjs";
|
|
12
12
|
import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.cjs";
|
|
13
13
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, getDependencySourceInfo, isDependencySource, isDerivedValueParser } from "./internal/dependency.cjs";
|
|
14
|
-
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
14
|
+
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, HelpSectionsOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
|
|
15
15
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.cjs";
|
|
16
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
16
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HelpSectionsOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ import { DeferredValue, DeferredValueOptions, DeferredValueSource, FluentParser,
|
|
|
11
11
|
import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, SeqOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.js";
|
|
12
12
|
import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./context.js";
|
|
13
13
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, getDependencySourceInfo, isDependencySource, isDerivedValueParser } from "./internal/dependency.js";
|
|
14
|
-
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
14
|
+
import { CommandListMode, CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, HelpSectionsOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
|
|
15
15
|
import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.js";
|
|
16
|
-
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
|
16
|
+
export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandListMode, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DeferredValue, DeferredValueOptions, DeferredValueSource, DependencyMode, DependencySource, DependencySourceInfo, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DetailedParseResult, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EffectfulCompletionSession, EmailOptions, ErrorLabelTerm, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HelpSectionsOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, LabelTerm, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageFormatter, type MessageFormatterOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, OriginOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ProgramNameTerm, RegExpOptions, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, SyntaxPunctuationTerm, TerminalColor, TerminalFormatContext, TerminalFormatter, TerminalFragment, TerminalStyle, TerminalTerm, TerminalTheme, TransformMapping, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, biject, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createMessageFormatter, createParserContext, cron, deduplicateDocEntries, deduplicateDocFragments, defaultTerminalTheme, deferredValue, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDependencySourceInfo, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredValue, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, origin, parse, parseAsync, parseDetailed, parseSync, passThrough, port, portRange, pwsh, regExp, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, transform, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.4.0-dev.
|
|
3
|
+
"version": "1.4.0-dev.2623",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -237,7 +237,7 @@
|
|
|
237
237
|
},
|
|
238
238
|
"sideEffects": false,
|
|
239
239
|
"devDependencies": {
|
|
240
|
-
"@optique/env": "1.4.0-dev.
|
|
240
|
+
"@optique/env": "1.4.0-dev.2623+c24ee8fb",
|
|
241
241
|
"@types/node": "^24.0.0",
|
|
242
242
|
"fast-check": "^4.7.0",
|
|
243
243
|
"tsdown": "^0.13.0",
|
package/skills/optique/SKILL.md
CHANGED
|
@@ -11,8 +11,7 @@ description: >
|
|
|
11
11
|
license: MIT
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
Start at <https://optique.dev/llms.txt>
|
|
15
|
-
combinatorial parser model and common pitfalls offline.
|
|
14
|
+
Start at <https://optique.dev/llms.txt> online; these rules also work offline.
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
Core rules
|
|
@@ -30,11 +29,14 @@ Core rules
|
|
|
30
29
|
Pin `colors`/`maxWidth` in tests; defaults use terminal and environment.
|
|
31
30
|
- Compose parsers with `object()`, `tuple()`, `seq()`, `or()`, `merge()`, and
|
|
32
31
|
modifiers. Do not hand-write argument scanners around Optique parsers.
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
- For command/option help headings, set the runner's
|
|
33
|
+
`helpSections: { commands: "Commands", options: "Options" }`.
|
|
34
|
+
It groups untitled entries only on pages with visible commands. See
|
|
35
|
+
<https://optique.dev/cookbook.md#command-and-option-headings-in-help>.
|
|
36
|
+
- Let TypeScript infer results unless another API needs a separate interface.
|
|
37
|
+
- Parsers are usually required. `optional(p)` yields `undefined`, and
|
|
38
|
+
`withDefault(p, value)` supplies a fallback. Use
|
|
39
|
+
`withDefault(flag("--name"), false)` for optional Boolean flags.
|
|
38
40
|
- Use semantic `message` helpers for descriptions and errors. Since 1.3.0,
|
|
39
41
|
customize terminal output with `theme` or `messageFormatter`, preserving
|
|
40
42
|
`initialWidth`, quoting, and width options. Keep canonical errors unthemed.
|
|
@@ -43,10 +45,9 @@ Core rules
|
|
|
43
45
|
parsing. Use `regExp({ flags })` for user-supplied sources, `biject()` for
|
|
44
46
|
one-to-one string-to-value choices, and `transform()` when an existing
|
|
45
47
|
value parser describes the accepted CLI spelling but your app needs a
|
|
46
|
-
different result type. Use `path()` from
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
not cover the domain.
|
|
48
|
+
different result type. Use `path()` from `@optique/run/valueparser` for
|
|
49
|
+
file-system paths. Write a custom `{ mode, metavar, parse, format }` value
|
|
50
|
+
parser only when the catalog does not cover the domain.
|
|
50
51
|
- Since 1.4.0, `-p8080`/`-vp8080` accept attached values. Values consume
|
|
51
52
|
the literal suffix (`-p=5` gives `"=5"`); full single-dash names win.
|
|
52
53
|
- Async value parsers like *@optique/git* make containing parsers async.
|
|
@@ -231,9 +232,8 @@ const parser = logLevel();
|
|
|
231
232
|
Common mistakes checklist
|
|
232
233
|
-------------------------
|
|
233
234
|
|
|
234
|
-
-
|
|
235
|
-
|
|
236
|
-
in tests and embedded use.
|
|
235
|
+
- Pass parsers to `run()` for apps; use explicit argument arrays with
|
|
236
|
+
`parse()` in tests and embedded use. Do not pre-parse `process.argv`.
|
|
237
237
|
- Do not treat `or(a, b)` as “zero or more alternatives.” It requires one
|
|
238
238
|
matching branch unless the whole `or()` is wrapped in `optional()` or
|
|
239
239
|
`withDefault()`.
|