@optique/core 1.0.0-dev.1227 → 1.0.0-dev.1236

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
@@ -678,7 +678,11 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
678
678
  sectionOrder
679
679
  }));
680
680
  }
681
- return require_mode_dispatch.dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
681
+ return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
682
+ const result = callOnError(1);
683
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
684
+ return result;
685
+ }, async () => callOnError(1));
682
686
  }
683
687
  const shell = availableShells[shellName];
684
688
  if (!shell) {
@@ -691,19 +695,29 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
691
695
  colors,
692
696
  quotes: !colors
693
697
  }));
694
- return require_mode_dispatch.dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
698
+ return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
699
+ const result = callOnError(1);
700
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
701
+ return result;
702
+ }, async () => callOnError(1));
695
703
  }
696
704
  if (args.length === 0) {
697
705
  const completionArg = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
698
706
  const script = shell.generateScript(programName, [completionArg, shellName]);
699
707
  stdout(script);
700
- return require_mode_dispatch.dispatchByMode(parser.$mode, () => callOnCompletion(0), () => Promise.resolve(callOnCompletion(0)));
708
+ return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
709
+ const result = callOnCompletion(0);
710
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
711
+ return result;
712
+ }, async () => callOnCompletion(0));
701
713
  }
702
714
  return require_mode_dispatch.dispatchByMode(parser.$mode, () => {
703
715
  const syncParser = parser;
704
716
  const suggestions = require_parser.suggest(syncParser, args);
705
717
  for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
706
- return callOnCompletion(0);
718
+ const result = callOnCompletion(0);
719
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
720
+ return result;
707
721
  }, async () => {
708
722
  const suggestions = await require_parser.suggestAsync(parser, args);
709
723
  for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
@@ -1090,9 +1104,12 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1090
1104
  * @param args The command-line arguments to parse.
1091
1105
  * @param options Configuration options for customizing behavior.
1092
1106
  * @returns The parsed result if successful.
1107
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1108
+ * {@link runParser} or {@link runParserAsync} for async parsers.
1093
1109
  * @since 0.9.0
1094
1110
  */
1095
1111
  function runParserSync(parser, programName, args, options) {
1112
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runParserSync(). Use runParser() or runParserAsync() instead.");
1096
1113
  return runParser(parser, programName, args, options);
1097
1114
  }
1098
1115
  /**
@@ -1451,11 +1468,14 @@ async function runWith(parser, programName, contexts, options) {
1451
1468
  * @param contexts Source contexts to use (priority: earlier overrides later).
1452
1469
  * @param options Run options including args, help, version, etc.
1453
1470
  * @returns The parsed result.
1454
- * @throws Error if any context returns a Promise or if a context's
1471
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1472
+ * {@link runWith} or {@link runWithAsync} for async parsers.
1473
+ * @throws {Error} If any context returns a Promise or if a context's
1455
1474
  * `[Symbol.asyncDispose]` returns a Promise.
1456
1475
  * @since 0.10.0
1457
1476
  */
1458
1477
  function runWithSync(parser, programName, contexts, options) {
1478
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1459
1479
  const args = options?.args ?? [];
1460
1480
  if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1461
1481
  if (contexts.length === 0) return runParser(parser, programName, args, options);
package/dist/facade.d.cts CHANGED
@@ -301,6 +301,8 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
301
301
  * @param args The command-line arguments to parse.
302
302
  * @param options Configuration options for customizing behavior.
303
303
  * @returns The parsed result if successful.
304
+ * @throws {TypeError} If an async parser is passed at runtime. Use
305
+ * {@link runParser} or {@link runParserAsync} for async parsers.
304
306
  * @since 0.9.0
305
307
  */
306
308
  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>;
@@ -461,7 +463,9 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
461
463
  * @param contexts Source contexts to use (priority: earlier overrides later).
462
464
  * @param options Run options including args, help, version, etc.
463
465
  * @returns The parsed result.
464
- * @throws Error if any context returns a Promise or if a context's
466
+ * @throws {TypeError} If an async parser is passed at runtime. Use
467
+ * {@link runWith} or {@link runWithAsync} for async parsers.
468
+ * @throws {Error} If any context returns a Promise or if a context's
465
469
  * `[Symbol.asyncDispose]` returns a Promise.
466
470
  * @since 0.10.0
467
471
  */
package/dist/facade.d.ts CHANGED
@@ -301,6 +301,8 @@ declare function runParser<TParser extends Parser<Mode, unknown, unknown>, THelp
301
301
  * @param args The command-line arguments to parse.
302
302
  * @param options Configuration options for customizing behavior.
303
303
  * @returns The parsed result if successful.
304
+ * @throws {TypeError} If an async parser is passed at runtime. Use
305
+ * {@link runParser} or {@link runParserAsync} for async parsers.
304
306
  * @since 0.9.0
305
307
  */
306
308
  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>;
@@ -461,7 +463,9 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
461
463
  * @param contexts Source contexts to use (priority: earlier overrides later).
462
464
  * @param options Run options including args, help, version, etc.
463
465
  * @returns The parsed result.
464
- * @throws Error if any context returns a Promise or if a context's
466
+ * @throws {TypeError} If an async parser is passed at runtime. Use
467
+ * {@link runWith} or {@link runWithAsync} for async parsers.
468
+ * @throws {Error} If any context returns a Promise or if a context's
465
469
  * `[Symbol.asyncDispose]` returns a Promise.
466
470
  * @since 0.10.0
467
471
  */
package/dist/facade.js CHANGED
@@ -678,7 +678,11 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
678
678
  sectionOrder
679
679
  }));
680
680
  }
681
- return dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
681
+ return dispatchByMode(parser.$mode, () => {
682
+ const result = callOnError(1);
683
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
684
+ return result;
685
+ }, async () => callOnError(1));
682
686
  }
683
687
  const shell = availableShells[shellName];
684
688
  if (!shell) {
@@ -691,19 +695,29 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
691
695
  colors,
692
696
  quotes: !colors
693
697
  }));
694
- return dispatchByMode(parser.$mode, () => callOnError(1), () => Promise.resolve(callOnError(1)));
698
+ return dispatchByMode(parser.$mode, () => {
699
+ const result = callOnError(1);
700
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
701
+ return result;
702
+ }, async () => callOnError(1));
695
703
  }
696
704
  if (args.length === 0) {
697
705
  const completionArg = isOptionMode ? completionOptionDisplayName ?? "--completion" : completionCommandDisplayName ?? "completion";
698
706
  const script = shell.generateScript(programName, [completionArg, shellName]);
699
707
  stdout(script);
700
- return dispatchByMode(parser.$mode, () => callOnCompletion(0), () => Promise.resolve(callOnCompletion(0)));
708
+ return dispatchByMode(parser.$mode, () => {
709
+ const result = callOnCompletion(0);
710
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
711
+ return result;
712
+ }, async () => callOnCompletion(0));
701
713
  }
702
714
  return dispatchByMode(parser.$mode, () => {
703
715
  const syncParser = parser;
704
716
  const suggestions = suggest(syncParser, args);
705
717
  for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
706
- return callOnCompletion(0);
718
+ const result = callOnCompletion(0);
719
+ if (result instanceof Promise) throw new RunParserError("Synchronous parser returned async result.");
720
+ return result;
707
721
  }, async () => {
708
722
  const suggestions = await suggestAsync(parser, args);
709
723
  for (const chunk of shell.encodeSuggestions(suggestions)) stdout(chunk);
@@ -1090,9 +1104,12 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
1090
1104
  * @param args The command-line arguments to parse.
1091
1105
  * @param options Configuration options for customizing behavior.
1092
1106
  * @returns The parsed result if successful.
1107
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1108
+ * {@link runParser} or {@link runParserAsync} for async parsers.
1093
1109
  * @since 0.9.0
1094
1110
  */
1095
1111
  function runParserSync(parser, programName, args, options) {
1112
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runParserSync(). Use runParser() or runParserAsync() instead.");
1096
1113
  return runParser(parser, programName, args, options);
1097
1114
  }
1098
1115
  /**
@@ -1451,11 +1468,14 @@ async function runWith(parser, programName, contexts, options) {
1451
1468
  * @param contexts Source contexts to use (priority: earlier overrides later).
1452
1469
  * @param options Run options including args, help, version, etc.
1453
1470
  * @returns The parsed result.
1454
- * @throws Error if any context returns a Promise or if a context's
1471
+ * @throws {TypeError} If an async parser is passed at runtime. Use
1472
+ * {@link runWith} or {@link runWithAsync} for async parsers.
1473
+ * @throws {Error} If any context returns a Promise or if a context's
1455
1474
  * `[Symbol.asyncDispose]` returns a Promise.
1456
1475
  * @since 0.10.0
1457
1476
  */
1458
1477
  function runWithSync(parser, programName, contexts, options) {
1478
+ if (parser.$mode !== "sync") throw new TypeError("Cannot use an async parser with runWithSync(). Use runWith() or runWithAsync() instead.");
1459
1479
  const args = options?.args ?? [];
1460
1480
  if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
1461
1481
  if (contexts.length === 0) return runParser(parser, programName, args, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1227+f9861245",
3
+ "version": "1.0.0-dev.1236+3ee9891d",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",