@optique/core 1.2.0-dev.2282 → 1.2.0-dev.2287
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/doc.cjs +3 -2
- package/dist/doc.d.cts +7 -0
- package/dist/doc.d.ts +7 -0
- package/dist/doc.js +3 -2
- package/dist/facade.cjs +10 -6
- package/dist/facade.d.cts +11 -0
- package/dist/facade.d.ts +11 -0
- package/dist/facade.js +10 -6
- package/package.json +2 -2
- package/skills/optique/SKILL.md +5 -3
package/dist/doc.cjs
CHANGED
|
@@ -214,6 +214,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
214
214
|
require_validate.validateProgramName(programName);
|
|
215
215
|
const termIndent = options.termIndent ?? 2;
|
|
216
216
|
const termWidth = options.termWidth ?? 26;
|
|
217
|
+
const showUsage = options.showUsage ?? true;
|
|
217
218
|
if (options.maxWidth != null && (!Number.isFinite(options.maxWidth) || !Number.isInteger(options.maxWidth))) throw new TypeError(`maxWidth must be a finite integer, got ${options.maxWidth}.`);
|
|
218
219
|
const filteredSections = page.sections.map((s) => ({
|
|
219
220
|
...s,
|
|
@@ -250,7 +251,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
250
251
|
const fixedEntryMin = termIndent + 2 + termWidth + minDescWidth;
|
|
251
252
|
const entryMin = needsDescColumn ? Math.min(splitEntryMin, fixedEntryMin) : hasEntries ? termIndent + 1 : 1;
|
|
252
253
|
const programNameWidth = require_displaywidth.getDisplayWidth(programName);
|
|
253
|
-
const usageMin = page.usage != null ? 7 + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage), programNameWidth + 7)) : 1;
|
|
254
|
+
const usageMin = page.usage != null && showUsage ? 7 + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage), programNameWidth + 7)) : 1;
|
|
254
255
|
let sectionMin = 1;
|
|
255
256
|
if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, 9);
|
|
256
257
|
if (hasContent(page.author)) sectionMin = Math.max(sectionMin, 7);
|
|
@@ -282,7 +283,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
282
283
|
});
|
|
283
284
|
output += "\n";
|
|
284
285
|
}
|
|
285
|
-
if (page.usage != null) {
|
|
286
|
+
if (page.usage != null && showUsage) {
|
|
286
287
|
const usageLabel = options.colors ? "\x1B[1;2mUsage:\x1B[0m " : "Usage: ";
|
|
287
288
|
output += usageLabel;
|
|
288
289
|
output += indentLines(require_usage.formatUsage(programName, page.usage, {
|
package/dist/doc.d.cts
CHANGED
|
@@ -225,6 +225,13 @@ interface DocPageFormatOptions {
|
|
|
225
225
|
* Maximum width of the entire formatted output.
|
|
226
226
|
*/
|
|
227
227
|
maxWidth?: number;
|
|
228
|
+
/**
|
|
229
|
+
* Whether to include the usage synopsis in the output.
|
|
230
|
+
*
|
|
231
|
+
* @default `true`
|
|
232
|
+
* @since 1.2.0
|
|
233
|
+
*/
|
|
234
|
+
showUsage?: boolean;
|
|
228
235
|
/**
|
|
229
236
|
* Whether and how to display default values for options and arguments.
|
|
230
237
|
*
|
package/dist/doc.d.ts
CHANGED
|
@@ -225,6 +225,13 @@ interface DocPageFormatOptions {
|
|
|
225
225
|
* Maximum width of the entire formatted output.
|
|
226
226
|
*/
|
|
227
227
|
maxWidth?: number;
|
|
228
|
+
/**
|
|
229
|
+
* Whether to include the usage synopsis in the output.
|
|
230
|
+
*
|
|
231
|
+
* @default `true`
|
|
232
|
+
* @since 1.2.0
|
|
233
|
+
*/
|
|
234
|
+
showUsage?: boolean;
|
|
228
235
|
/**
|
|
229
236
|
* Whether and how to display default values for options and arguments.
|
|
230
237
|
*
|
package/dist/doc.js
CHANGED
|
@@ -214,6 +214,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
214
214
|
validateProgramName(programName);
|
|
215
215
|
const termIndent = options.termIndent ?? 2;
|
|
216
216
|
const termWidth = options.termWidth ?? 26;
|
|
217
|
+
const showUsage = options.showUsage ?? true;
|
|
217
218
|
if (options.maxWidth != null && (!Number.isFinite(options.maxWidth) || !Number.isInteger(options.maxWidth))) throw new TypeError(`maxWidth must be a finite integer, got ${options.maxWidth}.`);
|
|
218
219
|
const filteredSections = page.sections.map((s) => ({
|
|
219
220
|
...s,
|
|
@@ -250,7 +251,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
250
251
|
const fixedEntryMin = termIndent + 2 + termWidth + minDescWidth;
|
|
251
252
|
const entryMin = needsDescColumn ? Math.min(splitEntryMin, fixedEntryMin) : hasEntries ? termIndent + 1 : 1;
|
|
252
253
|
const programNameWidth = getDisplayWidth(programName);
|
|
253
|
-
const usageMin = page.usage != null ? 7 + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage), programNameWidth + 7)) : 1;
|
|
254
|
+
const usageMin = page.usage != null && showUsage ? 7 + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage), programNameWidth + 7)) : 1;
|
|
254
255
|
let sectionMin = 1;
|
|
255
256
|
if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, 9);
|
|
256
257
|
if (hasContent(page.author)) sectionMin = Math.max(sectionMin, 7);
|
|
@@ -282,7 +283,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
282
283
|
});
|
|
283
284
|
output += "\n";
|
|
284
285
|
}
|
|
285
|
-
if (page.usage != null) {
|
|
286
|
+
if (page.usage != null && showUsage) {
|
|
286
287
|
const usageLabel = options.colors ? "\x1B[1;2mUsage:\x1B[0m " : "Usage: ";
|
|
287
288
|
output += usageLabel;
|
|
288
289
|
output += indentLines(formatUsage(programName, page.usage, {
|
package/dist/facade.cjs
CHANGED
|
@@ -608,7 +608,7 @@ function classifyParseFailure(failure, helpOptionNames, helpCommandNames, versio
|
|
|
608
608
|
* Handles shell completion requests.
|
|
609
609
|
* @since 0.6.0
|
|
610
610
|
*/
|
|
611
|
-
function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, rootOptionSuggestions = []) {
|
|
611
|
+
function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, showUsage, rootOptionSuggestions = []) {
|
|
612
612
|
const shellName = completionArgs[0] || "";
|
|
613
613
|
const args = completionArgs.slice(1);
|
|
614
614
|
const callOnError = (code) => onError(code);
|
|
@@ -621,7 +621,8 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
621
621
|
if (doc) stderr(require_doc.formatDocPage(programName, doc, {
|
|
622
622
|
colors,
|
|
623
623
|
maxWidth,
|
|
624
|
-
sectionOrder
|
|
624
|
+
sectionOrder,
|
|
625
|
+
showUsage
|
|
625
626
|
}));
|
|
626
627
|
}
|
|
627
628
|
return require_mode_dispatch.dispatchByMode(parser.mode, () => {
|
|
@@ -948,7 +949,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
948
949
|
options = optionsParam ?? {};
|
|
949
950
|
}
|
|
950
951
|
require_validate.validateProgramName(programName);
|
|
951
|
-
const { colors, maxWidth, showDefault, showChoices, sectionOrder, aboveError = "usage", onError = () => {
|
|
952
|
+
const { colors, maxWidth, showDefault, showChoices, sectionOrder, showUsage, aboveError = "usage", onError = () => {
|
|
952
953
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
953
954
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
954
955
|
const norm = (c) => c === true ? {} : c;
|
|
@@ -1051,7 +1052,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1051
1052
|
classified.shell,
|
|
1052
1053
|
...classified.commandPath ?? [],
|
|
1053
1054
|
...classified.args
|
|
1054
|
-
], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, rootOptionSuggestions);
|
|
1055
|
+
], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, showUsage, rootOptionSuggestions);
|
|
1055
1056
|
case "help": {
|
|
1056
1057
|
let helpGeneratorParser;
|
|
1057
1058
|
let docGeneratorParser;
|
|
@@ -1134,7 +1135,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1134
1135
|
maxWidth,
|
|
1135
1136
|
showDefault,
|
|
1136
1137
|
showChoices,
|
|
1137
|
-
sectionOrder
|
|
1138
|
+
sectionOrder,
|
|
1139
|
+
showUsage
|
|
1138
1140
|
}));
|
|
1139
1141
|
}
|
|
1140
1142
|
return onHelp(0);
|
|
@@ -1201,7 +1203,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1201
1203
|
colors,
|
|
1202
1204
|
maxWidth,
|
|
1203
1205
|
showDefault,
|
|
1204
|
-
showChoices
|
|
1206
|
+
showChoices,
|
|
1207
|
+
sectionOrder,
|
|
1208
|
+
showUsage
|
|
1205
1209
|
}));
|
|
1206
1210
|
}
|
|
1207
1211
|
if (effectiveAboveError === "usage") stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
|
package/dist/facade.d.cts
CHANGED
|
@@ -105,6 +105,17 @@ interface RunOptions<THelp, TError> {
|
|
|
105
105
|
* @since 0.10.0
|
|
106
106
|
*/
|
|
107
107
|
readonly showChoices?: boolean | ShowChoicesOptions;
|
|
108
|
+
/**
|
|
109
|
+
* Whether to include the usage synopsis in full help output.
|
|
110
|
+
*
|
|
111
|
+
* This affects help pages produced by `--help`, the help command, and
|
|
112
|
+
* `aboveError: "help"`. It does not suppress usage-only error preambles
|
|
113
|
+
* from `aboveError: "usage"`.
|
|
114
|
+
*
|
|
115
|
+
* @default `true`
|
|
116
|
+
* @since 1.2.0
|
|
117
|
+
*/
|
|
118
|
+
readonly showUsage?: boolean;
|
|
108
119
|
/**
|
|
109
120
|
* A custom comparator function to control the order of sections in the
|
|
110
121
|
* help output. When provided, it is used instead of the default smart
|
package/dist/facade.d.ts
CHANGED
|
@@ -105,6 +105,17 @@ interface RunOptions<THelp, TError> {
|
|
|
105
105
|
* @since 0.10.0
|
|
106
106
|
*/
|
|
107
107
|
readonly showChoices?: boolean | ShowChoicesOptions;
|
|
108
|
+
/**
|
|
109
|
+
* Whether to include the usage synopsis in full help output.
|
|
110
|
+
*
|
|
111
|
+
* This affects help pages produced by `--help`, the help command, and
|
|
112
|
+
* `aboveError: "help"`. It does not suppress usage-only error preambles
|
|
113
|
+
* from `aboveError: "usage"`.
|
|
114
|
+
*
|
|
115
|
+
* @default `true`
|
|
116
|
+
* @since 1.2.0
|
|
117
|
+
*/
|
|
118
|
+
readonly showUsage?: boolean;
|
|
108
119
|
/**
|
|
109
120
|
* A custom comparator function to control the order of sections in the
|
|
110
121
|
* help output. When provided, it is used instead of the default smart
|
package/dist/facade.js
CHANGED
|
@@ -608,7 +608,7 @@ function classifyParseFailure(failure, helpOptionNames, helpCommandNames, versio
|
|
|
608
608
|
* Handles shell completion requests.
|
|
609
609
|
* @since 0.6.0
|
|
610
610
|
*/
|
|
611
|
-
function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, rootOptionSuggestions = []) {
|
|
611
|
+
function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, showUsage, rootOptionSuggestions = []) {
|
|
612
612
|
const shellName = completionArgs[0] || "";
|
|
613
613
|
const args = completionArgs.slice(1);
|
|
614
614
|
const callOnError = (code) => onError(code);
|
|
@@ -621,7 +621,8 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
|
|
|
621
621
|
if (doc) stderr(formatDocPage(programName, doc, {
|
|
622
622
|
colors,
|
|
623
623
|
maxWidth,
|
|
624
|
-
sectionOrder
|
|
624
|
+
sectionOrder,
|
|
625
|
+
showUsage
|
|
625
626
|
}));
|
|
626
627
|
}
|
|
627
628
|
return dispatchByMode(parser.mode, () => {
|
|
@@ -948,7 +949,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
948
949
|
options = optionsParam ?? {};
|
|
949
950
|
}
|
|
950
951
|
validateProgramName(programName);
|
|
951
|
-
const { colors, maxWidth, showDefault, showChoices, sectionOrder, aboveError = "usage", onError = () => {
|
|
952
|
+
const { colors, maxWidth, showDefault, showChoices, sectionOrder, showUsage, aboveError = "usage", onError = () => {
|
|
952
953
|
throw new RunParserError("Failed to parse command line arguments.");
|
|
953
954
|
}, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
|
|
954
955
|
const norm = (c) => c === true ? {} : c;
|
|
@@ -1051,7 +1052,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1051
1052
|
classified.shell,
|
|
1052
1053
|
...classified.commandPath ?? [],
|
|
1053
1054
|
...classified.args
|
|
1054
|
-
], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, rootOptionSuggestions);
|
|
1055
|
+
], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, showUsage, rootOptionSuggestions);
|
|
1055
1056
|
case "help": {
|
|
1056
1057
|
let helpGeneratorParser;
|
|
1057
1058
|
let docGeneratorParser;
|
|
@@ -1134,7 +1135,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1134
1135
|
maxWidth,
|
|
1135
1136
|
showDefault,
|
|
1136
1137
|
showChoices,
|
|
1137
|
-
sectionOrder
|
|
1138
|
+
sectionOrder,
|
|
1139
|
+
showUsage
|
|
1138
1140
|
}));
|
|
1139
1141
|
}
|
|
1140
1142
|
return onHelp(0);
|
|
@@ -1201,7 +1203,9 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
|
|
|
1201
1203
|
colors,
|
|
1202
1204
|
maxWidth,
|
|
1203
1205
|
showDefault,
|
|
1204
|
-
showChoices
|
|
1206
|
+
showChoices,
|
|
1207
|
+
sectionOrder,
|
|
1208
|
+
showUsage
|
|
1205
1209
|
}));
|
|
1206
1210
|
}
|
|
1207
1211
|
if (effectiveAboveError === "usage") stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/core",
|
|
3
|
-
"version": "1.2.0-dev.
|
|
3
|
+
"version": "1.2.0-dev.2287",
|
|
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.2.0-dev.
|
|
228
|
+
"@optique/env": "1.2.0-dev.2287+86d0fd20"
|
|
229
229
|
},
|
|
230
230
|
"scripts": {
|
|
231
231
|
"build": "tsdown",
|
package/skills/optique/SKILL.md
CHANGED
|
@@ -22,7 +22,7 @@ they cover the parts agents most often get wrong.
|
|
|
22
22
|
Core rules
|
|
23
23
|
----------
|
|
24
24
|
|
|
25
|
-
- Use `run()` from
|
|
25
|
+
- Use `run()` from *@optique/run* for real CLI applications. It reads
|
|
26
26
|
`process.argv`/`Deno.args`, handles help, version output, errors, exit
|
|
27
27
|
codes, colors, terminal width, and shell completion. Use `parse()` from
|
|
28
28
|
`@optique/core/parser` or `runParser()` from `@optique/core/facade` when
|
|
@@ -37,7 +37,7 @@ Core rules
|
|
|
37
37
|
`undefined`; `withDefault(p, value)` yields a fallback value. For Boolean
|
|
38
38
|
flags, use `withDefault(flag("--name"), false)` when absence should mean
|
|
39
39
|
`false`.
|
|
40
|
-
- Use `message` from
|
|
40
|
+
- Use `message` from *@optique/core/message* for descriptions, help text, and
|
|
41
41
|
custom errors. Prefer semantic message helpers such as `optionName()` and
|
|
42
42
|
`metavar()` over string concatenation when naming CLI elements.
|
|
43
43
|
- Use value parsers such as `integer()`, `choice()`, `url()`, and `uuid()`
|
|
@@ -46,13 +46,15 @@ Core rules
|
|
|
46
46
|
`{ mode, metavar, parse, format }` value parser only when the catalog does
|
|
47
47
|
not cover the domain.
|
|
48
48
|
- Async value parsers make the containing parser async. If you use packages
|
|
49
|
-
such as
|
|
49
|
+
such as *@optique/git*, remember to `await run(...)`, `await parse(...)`, or
|
|
50
50
|
`await runParser(...)` as appropriate.
|
|
51
51
|
- Build subcommands with `command()` combined by `or()`. Put a literal field
|
|
52
52
|
such as `command: constant("serve")` in each branch when you want a
|
|
53
53
|
discriminated union.
|
|
54
54
|
- Enable completion through `run(parser, { completion: "both" })` for CLI
|
|
55
55
|
apps. Do not hand-write completion scripts from parser metadata.
|
|
56
|
+
- Use `showUsage: false` in runner options when full help should show the
|
|
57
|
+
brief and command or option sections without the `Usage:` synopsis.
|
|
56
58
|
|
|
57
59
|
|
|
58
60
|
Canonical app shape
|