@optique/core 0.10.0-dev.342 → 0.10.0-dev.344

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
@@ -660,6 +660,43 @@ function indentLines(text$1, indent) {
660
660
  return text$1.split("\n").join("\n" + " ".repeat(indent));
661
661
  }
662
662
  /**
663
+ * Checks if the arguments contain help, version, or completion requests
664
+ * that should be handled immediately without context processing.
665
+ *
666
+ * This enables early exit optimization: when users request help, version,
667
+ * or completion, we skip annotation collection and context processing
668
+ * entirely, delegating directly to runParser().
669
+ *
670
+ * @param args Command-line arguments to check.
671
+ * @param options Run options containing help/version/completion configuration.
672
+ * @returns `true` if early exit should be performed, `false` otherwise.
673
+ */
674
+ function needsEarlyExit(args, options) {
675
+ if (options.help) {
676
+ const helpMode = options.help.mode ?? "option";
677
+ if ((helpMode === "option" || helpMode === "both") && args.includes("--help")) return true;
678
+ if ((helpMode === "command" || helpMode === "both") && args[0] === "help") return true;
679
+ }
680
+ if (options.version) {
681
+ const versionMode = options.version.mode ?? "option";
682
+ if ((versionMode === "option" || versionMode === "both") && args.includes("--version")) return true;
683
+ if ((versionMode === "command" || versionMode === "both") && args[0] === "version") return true;
684
+ }
685
+ if (options.completion) {
686
+ const completionMode = options.completion.mode ?? "both";
687
+ const completionName = options.completion.name ?? "both";
688
+ if (completionMode === "command" || completionMode === "both") {
689
+ if ((completionName === "singular" || completionName === "both") && args[0] === "completion") return true;
690
+ if ((completionName === "plural" || completionName === "both") && args[0] === "completions") return true;
691
+ }
692
+ if (completionMode === "option" || completionMode === "both") for (const arg of args) {
693
+ if ((completionName === "singular" || completionName === "both") && (arg === "--completion" || arg.startsWith("--completion="))) return true;
694
+ if ((completionName === "plural" || completionName === "both") && (arg === "--completions" || arg.startsWith("--completions="))) return true;
695
+ }
696
+ }
697
+ return false;
698
+ }
699
+ /**
663
700
  * Merges multiple annotation objects, with earlier contexts having priority.
664
701
  *
665
702
  * When the same symbol key exists in multiple annotations, the value from
@@ -779,6 +816,10 @@ function hasDynamicContexts(contexts) {
779
816
  */
780
817
  async function runWith(parser, programName, contexts, options) {
781
818
  const args = options?.args ?? [];
819
+ if (needsEarlyExit(args, options)) {
820
+ if (parser.$mode === "async") return runParser(parser, programName, args, options);
821
+ return Promise.resolve(runParser(parser, programName, args, options));
822
+ }
782
823
  if (contexts.length === 0) {
783
824
  if (parser.$mode === "async") return runParser(parser, programName, args, options);
784
825
  return Promise.resolve(runParser(parser, programName, args, options));
@@ -834,6 +875,7 @@ async function runWith(parser, programName, contexts, options) {
834
875
  */
835
876
  function runWithSync(parser, programName, contexts, options) {
836
877
  const args = options?.args ?? [];
878
+ if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
837
879
  if (contexts.length === 0) return runParser(parser, programName, args, options);
838
880
  const phase1Annotations = collectAnnotationsSync(contexts);
839
881
  const needsTwoPhase = hasDynamicContexts(contexts);
package/dist/facade.js CHANGED
@@ -660,6 +660,43 @@ function indentLines(text$1, indent) {
660
660
  return text$1.split("\n").join("\n" + " ".repeat(indent));
661
661
  }
662
662
  /**
663
+ * Checks if the arguments contain help, version, or completion requests
664
+ * that should be handled immediately without context processing.
665
+ *
666
+ * This enables early exit optimization: when users request help, version,
667
+ * or completion, we skip annotation collection and context processing
668
+ * entirely, delegating directly to runParser().
669
+ *
670
+ * @param args Command-line arguments to check.
671
+ * @param options Run options containing help/version/completion configuration.
672
+ * @returns `true` if early exit should be performed, `false` otherwise.
673
+ */
674
+ function needsEarlyExit(args, options) {
675
+ if (options.help) {
676
+ const helpMode = options.help.mode ?? "option";
677
+ if ((helpMode === "option" || helpMode === "both") && args.includes("--help")) return true;
678
+ if ((helpMode === "command" || helpMode === "both") && args[0] === "help") return true;
679
+ }
680
+ if (options.version) {
681
+ const versionMode = options.version.mode ?? "option";
682
+ if ((versionMode === "option" || versionMode === "both") && args.includes("--version")) return true;
683
+ if ((versionMode === "command" || versionMode === "both") && args[0] === "version") return true;
684
+ }
685
+ if (options.completion) {
686
+ const completionMode = options.completion.mode ?? "both";
687
+ const completionName = options.completion.name ?? "both";
688
+ if (completionMode === "command" || completionMode === "both") {
689
+ if ((completionName === "singular" || completionName === "both") && args[0] === "completion") return true;
690
+ if ((completionName === "plural" || completionName === "both") && args[0] === "completions") return true;
691
+ }
692
+ if (completionMode === "option" || completionMode === "both") for (const arg of args) {
693
+ if ((completionName === "singular" || completionName === "both") && (arg === "--completion" || arg.startsWith("--completion="))) return true;
694
+ if ((completionName === "plural" || completionName === "both") && (arg === "--completions" || arg.startsWith("--completions="))) return true;
695
+ }
696
+ }
697
+ return false;
698
+ }
699
+ /**
663
700
  * Merges multiple annotation objects, with earlier contexts having priority.
664
701
  *
665
702
  * When the same symbol key exists in multiple annotations, the value from
@@ -779,6 +816,10 @@ function hasDynamicContexts(contexts) {
779
816
  */
780
817
  async function runWith(parser, programName, contexts, options) {
781
818
  const args = options?.args ?? [];
819
+ if (needsEarlyExit(args, options)) {
820
+ if (parser.$mode === "async") return runParser(parser, programName, args, options);
821
+ return Promise.resolve(runParser(parser, programName, args, options));
822
+ }
782
823
  if (contexts.length === 0) {
783
824
  if (parser.$mode === "async") return runParser(parser, programName, args, options);
784
825
  return Promise.resolve(runParser(parser, programName, args, options));
@@ -834,6 +875,7 @@ async function runWith(parser, programName, contexts, options) {
834
875
  */
835
876
  function runWithSync(parser, programName, contexts, options) {
836
877
  const args = options?.args ?? [];
878
+ if (needsEarlyExit(args, options)) return runParser(parser, programName, args, options);
837
879
  if (contexts.length === 0) return runParser(parser, programName, args, options);
838
880
  const phase1Annotations = collectAnnotationsSync(contexts);
839
881
  const needsTwoPhase = hasDynamicContexts(contexts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.10.0-dev.342+b6648cfd",
3
+ "version": "0.10.0-dev.344+5ee5e55e",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",