@optique/core 1.4.0-dev.2606 → 1.4.0-dev.2608

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 CHANGED
@@ -517,7 +517,7 @@ function classifyParseFailure(failure, helpOptionNames, helpCommandNames, versio
517
517
  * Handles shell completion requests.
518
518
  * @since 0.6.0
519
519
  */
520
- function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, termWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, showUsage, rootOptionSuggestions = [], messageFormatter, theme, automaticWidth = false) {
520
+ function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, termWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, showUsage, rootOptionSuggestions = [], messageFormatter, theme, automaticWidth = false, errors) {
521
521
  const errorOptions = (format) => automaticWidth ? require_terminal_width.withAutomaticWidth(format, (width) => {
522
522
  maxWidth = width;
523
523
  }) : format;
@@ -526,7 +526,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
526
526
  const callOnError = (code, error) => onError(code, error);
527
527
  const callOnCompletion = (code) => onCompletion(code);
528
528
  if (!shellName) {
529
- const error = require_message.message`Missing shell name for completion.`;
529
+ const error = errors?.missingShell ?? require_message.message`Missing shell name for completion.`;
530
530
  const writeError = () => stderr(require_message_renderer.renderErrorMessage(error, errorOptions({
531
531
  messageFormatter,
532
532
  theme,
@@ -568,7 +568,8 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
568
568
  if (available.length > 0) available.push(require_message.text(", "));
569
569
  available.push(require_message.value(name));
570
570
  }
571
- const error = require_message.message`Unsupported shell ${shellName}. Available shells: ${available}.`;
571
+ const unsupportedShell = errors?.unsupportedShell;
572
+ const error = typeof unsupportedShell === "function" ? unsupportedShell(shellName, Object.keys(availableShells)) : unsupportedShell ?? require_message.message`Unsupported shell ${shellName}. Available shells: ${available}.`;
572
573
  stderr(require_message_renderer.renderErrorMessage(error, errorOptions({
573
574
  messageFormatter,
574
575
  theme,
@@ -1037,7 +1038,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1037
1038
  classified.shell,
1038
1039
  ...classified.commandPath ?? [],
1039
1040
  ...classified.args
1040
- ], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, termWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, showUsage, rootOptionSuggestions, messageFormatter, theme, automaticWidth);
1041
+ ], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, termWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, showUsage, rootOptionSuggestions, messageFormatter, theme, automaticWidth, options.completion?.errors);
1041
1042
  case "help": {
1042
1043
  let helpGeneratorParser;
1043
1044
  let docGeneratorParser;
package/dist/facade.d.cts CHANGED
@@ -243,6 +243,24 @@ interface RunOptions<THelp, TError> {
243
243
  * @default `{ bash, fish, nu, pwsh, zsh }`
244
244
  */
245
245
  readonly shells?: Record<string, ShellCompletion>;
246
+ /**
247
+ * Custom messages for completion shell errors. Unspecified errors use
248
+ * the default messages.
249
+ * @since 1.4.0
250
+ */
251
+ readonly errors?: {
252
+ /**
253
+ * Message shown when no shell name is provided.
254
+ * @since 1.4.0
255
+ */
256
+ readonly missingShell?: Message;
257
+ /**
258
+ * Message shown for an unsupported shell. A callback receives the
259
+ * shell name and the available shell names, including custom shells.
260
+ * @since 1.4.0
261
+ */
262
+ readonly unsupportedShell?: Message | ((shell: string, availableShells: readonly string[]) => Message);
263
+ };
246
264
  /** Callback invoked when completion is requested. */
247
265
  readonly onShow?: (() => THelp) | ((exitCode: number) => THelp);
248
266
  } & ({
@@ -265,6 +283,7 @@ interface RunOptions<THelp, TError> {
265
283
  * Callback invoked after error output for a parse failure, an invalid
266
284
  * command path before help, or a missing or unsupported completion shell.
267
285
  * Receives the exit code and the structured error message used for output.
286
+ * Completion errors use `completion.errors` overrides when configured.
268
287
  * The message does not include the runner's `Error: ` prefix or usage/help
269
288
  * output. The runner preserves any formatting terms in the original message.
270
289
  *
package/dist/facade.d.ts CHANGED
@@ -243,6 +243,24 @@ interface RunOptions<THelp, TError> {
243
243
  * @default `{ bash, fish, nu, pwsh, zsh }`
244
244
  */
245
245
  readonly shells?: Record<string, ShellCompletion>;
246
+ /**
247
+ * Custom messages for completion shell errors. Unspecified errors use
248
+ * the default messages.
249
+ * @since 1.4.0
250
+ */
251
+ readonly errors?: {
252
+ /**
253
+ * Message shown when no shell name is provided.
254
+ * @since 1.4.0
255
+ */
256
+ readonly missingShell?: Message;
257
+ /**
258
+ * Message shown for an unsupported shell. A callback receives the
259
+ * shell name and the available shell names, including custom shells.
260
+ * @since 1.4.0
261
+ */
262
+ readonly unsupportedShell?: Message | ((shell: string, availableShells: readonly string[]) => Message);
263
+ };
246
264
  /** Callback invoked when completion is requested. */
247
265
  readonly onShow?: (() => THelp) | ((exitCode: number) => THelp);
248
266
  } & ({
@@ -265,6 +283,7 @@ interface RunOptions<THelp, TError> {
265
283
  * Callback invoked after error output for a parse failure, an invalid
266
284
  * command path before help, or a missing or unsupported completion shell.
267
285
  * Receives the exit code and the structured error message used for output.
286
+ * Completion errors use `completion.errors` overrides when configured.
268
287
  * The message does not include the runner's `Error: ` prefix or usage/help
269
288
  * output. The runner preserves any formatting terms in the original message.
270
289
  *
package/dist/facade.js CHANGED
@@ -517,7 +517,7 @@ function classifyParseFailure(failure, helpOptionNames, helpCommandNames, versio
517
517
  * Handles shell completion requests.
518
518
  * @since 0.6.0
519
519
  */
520
- function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, termWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, showUsage, rootOptionSuggestions = [], messageFormatter, theme, automaticWidth = false) {
520
+ function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, termWidth, completionCommandDisplayName, completionOptionDisplayName, isOptionMode, sectionOrder, showUsage, rootOptionSuggestions = [], messageFormatter, theme, automaticWidth = false, errors) {
521
521
  const errorOptions = (format) => automaticWidth ? withAutomaticWidth(format, (width) => {
522
522
  maxWidth = width;
523
523
  }) : format;
@@ -526,7 +526,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
526
526
  const callOnError = (code, error) => onError(code, error);
527
527
  const callOnCompletion = (code) => onCompletion(code);
528
528
  if (!shellName) {
529
- const error = message`Missing shell name for completion.`;
529
+ const error = errors?.missingShell ?? message`Missing shell name for completion.`;
530
530
  const writeError = () => stderr(renderErrorMessage(error, errorOptions({
531
531
  messageFormatter,
532
532
  theme,
@@ -568,7 +568,8 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
568
568
  if (available.length > 0) available.push(text(", "));
569
569
  available.push(value(name));
570
570
  }
571
- const error = message`Unsupported shell ${shellName}. Available shells: ${available}.`;
571
+ const unsupportedShell = errors?.unsupportedShell;
572
+ const error = typeof unsupportedShell === "function" ? unsupportedShell(shellName, Object.keys(availableShells)) : unsupportedShell ?? message`Unsupported shell ${shellName}. Available shells: ${available}.`;
572
573
  stderr(renderErrorMessage(error, errorOptions({
573
574
  messageFormatter,
574
575
  theme,
@@ -1037,7 +1038,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1037
1038
  classified.shell,
1038
1039
  ...classified.commandPath ?? [],
1039
1040
  ...classified.args
1040
- ], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, termWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, showUsage, rootOptionSuggestions, messageFormatter, theme, automaticWidth);
1041
+ ], programName, parser, classified.source === "command" ? completionParsers.completionCommand : completionParsers.completionOption, stdout, stderr, onCompletionResult, onErrorResult, availableShells, colors, maxWidth, termWidth, completionCommandNames[0], completionOptionNames[0], classified.source === "option", sectionOrder, showUsage, rootOptionSuggestions, messageFormatter, theme, automaticWidth, options.completion?.errors);
1041
1042
  case "help": {
1042
1043
  let helpGeneratorParser;
1043
1044
  let docGeneratorParser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.4.0-dev.2606",
3
+ "version": "1.4.0-dev.2608",
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.2606+b74e9130",
240
+ "@optique/env": "1.4.0-dev.2608+513a8817",
241
241
  "@types/node": "^24.0.0",
242
242
  "fast-check": "^4.7.0",
243
243
  "tsdown": "^0.13.0",
@@ -77,8 +77,8 @@ Core rules
77
77
  - Build subcommands with `command()` combined by `or()`. Put a literal field
78
78
  such as `command: constant("serve")` in each branch when you want a
79
79
  discriminated union.
80
- - Enable completion through `run(parser, { completion: "both" })` for CLI
81
- apps. Do not hand-write completion scripts from parser metadata.
80
+ - Use `run(parser, { completion: "both" })` for completion, or the object form
81
+ with `completion.errors` for custom shell errors. Do not hand-write scripts.
82
82
  - Use `usageLine: [{ type: "ellipsis" }]` in runner options when a large root
83
83
  synopsis should become a compact `Usage: myapp ...` line. This applies only
84
84
  to root full help; use `command()`'s `usageLine` for subcommand help.