@optique/core 1.4.0-dev.2607 → 1.4.0-dev.2611

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
@@ -12,7 +12,6 @@ const require_dependency_runtime = require('./dependency-runtime.cjs');
12
12
  const require_input_trace = require('./input-trace.cjs');
13
13
  const require_internal_parser = require('./internal/parser.cjs');
14
14
  const require_completion = require('./completion.cjs');
15
- const require_usage_internals = require('./usage-internals.cjs');
16
15
  const require_command_alias = require('./internal/command-alias.cjs');
17
16
  const require_phase2_seed = require('./phase2-seed.cjs');
18
17
  const require_modifiers = require('./modifiers.cjs');
@@ -518,7 +517,7 @@ function classifyParseFailure(failure, helpOptionNames, helpCommandNames, versio
518
517
  * Handles shell completion requests.
519
518
  * @since 0.6.0
520
519
  */
521
- 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) {
522
521
  const errorOptions = (format) => automaticWidth ? require_terminal_width.withAutomaticWidth(format, (width) => {
523
522
  maxWidth = width;
524
523
  }) : format;
@@ -527,7 +526,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
527
526
  const callOnError = (code, error) => onError(code, error);
528
527
  const callOnCompletion = (code) => onCompletion(code);
529
528
  if (!shellName) {
530
- const error = require_message.message`Missing shell name for completion.`;
529
+ const error = errors?.missingShell ?? require_message.message`Missing shell name for completion.`;
531
530
  const writeError = () => stderr(require_message_renderer.renderErrorMessage(error, errorOptions({
532
531
  messageFormatter,
533
532
  theme,
@@ -562,14 +561,15 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
562
561
  return result;
563
562
  }, async () => callOnError(1, error));
564
563
  }
565
- const shell = availableShells[shellName];
564
+ const shell = Object.hasOwn(availableShells, shellName) ? availableShells[shellName] : void 0;
566
565
  if (!shell) {
567
566
  const available = [];
568
567
  for (const name in availableShells) {
569
568
  if (available.length > 0) available.push(require_message.text(", "));
570
569
  available.push(require_message.value(name));
571
570
  }
572
- 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}.`;
573
573
  stderr(require_message_renderer.renderErrorMessage(error, errorOptions({
574
574
  messageFormatter,
575
575
  theme,
@@ -750,16 +750,83 @@ function collectActiveValueOptionNames(usage, commandPath, includeDirectAfterCom
750
750
  flag: /* @__PURE__ */ new Set()
751
751
  };
752
752
  if (commandPath.length === 0) {
753
- require_usage_internals.collectRootOptionNames(usage, optionNames, rootLeadingNames);
753
+ collectRootOptionNames(usage, optionNames, rootLeadingNames);
754
754
  return optionNames.value;
755
- } else require_usage_internals.collectActiveOptionNames(usage, commandPath, optionNames, false, includeDirectAfterCommandOptions);
755
+ } else collectActiveOptionNames(usage, commandPath, optionNames, false, includeDirectAfterCommandOptions);
756
756
  const names = new Set(optionNames.value);
757
757
  for (const name of optionNames.flag) names.delete(name);
758
758
  return names;
759
759
  }
760
+ function collectRootOptionNames(usage, names, rootLeadingNames) {
761
+ for (const term of usage) collectRootOptionNamesFromTerm(term, names, rootLeadingNames);
762
+ }
763
+ function collectRootOptionNamesFromTerm(term, names, rootLeadingNames) {
764
+ switch (term.type) {
765
+ case "option":
766
+ for (const name of term.names) {
767
+ if (!rootLeadingNames.has(name)) continue;
768
+ if (term.metavar != null) names.value.add(name);
769
+ else names.flag.add(name);
770
+ }
771
+ return;
772
+ case "optional":
773
+ case "multiple":
774
+ case "sequence":
775
+ collectRootOptionNames(term.terms, names, rootLeadingNames);
776
+ return;
777
+ case "exclusive":
778
+ for (const branch of term.terms) collectRootOptionNames(branch, names, rootLeadingNames);
779
+ return;
780
+ case "argument":
781
+ case "command":
782
+ case "literal":
783
+ case "passthrough":
784
+ case "ellipsis": return;
785
+ }
786
+ }
787
+ function collectActiveOptionNames(usage, commandPath, names, fromExclusive, includeDirectAfterCommandOptions) {
788
+ if (commandPath.length === 0) {
789
+ collectOptionNamesAtCurrentCommandDepth(usage, names, false);
790
+ return;
791
+ }
792
+ const [commandName, ...rest] = commandPath;
793
+ for (let i = 0; i < usage.length; i++) {
794
+ const term = usage[i];
795
+ if (term.type === "command" && term.name === commandName) {
796
+ const remainingUsage = usage.slice(i + 1);
797
+ if (rest.length === 0) collectOptionNamesAtCurrentCommandDepth(remainingUsage, names, !fromExclusive && includeDirectAfterCommandOptions);
798
+ else collectActiveOptionNames(remainingUsage, rest, names, fromExclusive, includeDirectAfterCommandOptions);
799
+ } else if (term.type === "exclusive") for (const branch of term.terms) collectActiveOptionNames(branch, commandPath, names, true, includeDirectAfterCommandOptions);
800
+ else if (term.type === "optional" || term.type === "multiple" || term.type === "sequence") collectActiveOptionNames(term.terms, commandPath, names, fromExclusive, includeDirectAfterCommandOptions);
801
+ }
802
+ }
760
803
  function isRootOptionToken(token, rootOptionSuggestions) {
761
804
  return token != null && rootOptionSuggestions.some((suggestion) => token === suggestion.text || token.startsWith(`${suggestion.text}=`));
762
805
  }
806
+ function collectOptionNamesAtCurrentCommandDepth(usage, names, afterMatchedCommand) {
807
+ for (const term of usage) if (collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand)) return;
808
+ }
809
+ function collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand) {
810
+ switch (term.type) {
811
+ case "command": return !afterMatchedCommand;
812
+ case "option":
813
+ if (term.metavar != null) for (const name of term.names) names.value.add(name);
814
+ else for (const name of term.names) names.flag.add(name);
815
+ return false;
816
+ case "optional":
817
+ case "multiple":
818
+ case "sequence":
819
+ collectOptionNamesAtCurrentCommandDepth(term.terms, names, afterMatchedCommand);
820
+ return false;
821
+ case "exclusive":
822
+ for (const branch of term.terms) collectOptionNamesAtCurrentCommandDepth(branch, names, false);
823
+ return false;
824
+ case "argument":
825
+ case "literal":
826
+ case "passthrough":
827
+ case "ellipsis": return false;
828
+ }
829
+ }
763
830
  function getRootMetaOptionSuggestions(helpOptionConfig, helpOptionNames, versionOptionConfig, versionOptionNames) {
764
831
  const suggestions = [];
765
832
  if (helpOptionConfig != null && !require_usage.isSuggestionHidden(helpOptionConfig.hidden)) suggestions.push(...helpOptionNames.map((name) => ({
@@ -971,7 +1038,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
971
1038
  classified.shell,
972
1039
  ...classified.commandPath ?? [],
973
1040
  ...classified.args
974
- ], 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);
975
1042
  case "help": {
976
1043
  let helpGeneratorParser;
977
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
@@ -12,7 +12,6 @@ import { collectExplicitSourceValues, collectExplicitSourceValuesAsync, createDe
12
12
  import { createInputTrace } from "./input-trace.js";
13
13
  import { attemptParseAsync, attemptParseSync, createEffectfulCompletionSession, createParserContext, getDocPage } from "./internal/parser.js";
14
14
  import { bash, fish, nu, pwsh, zsh } from "./completion.js";
15
- import { collectActiveOptionNames, collectRootOptionNames } from "./usage-internals.js";
16
15
  import { allowDuplicateLeadingCommandNamesKey, hiddenCommandAliasesKey } from "./internal/command-alias.js";
17
16
  import { completeOrExtractPhase2Seed } from "./phase2-seed.js";
18
17
  import { multiple, optional, withDefault } from "./modifiers.js";
@@ -518,7 +517,7 @@ function classifyParseFailure(failure, helpOptionNames, helpCommandNames, versio
518
517
  * Handles shell completion requests.
519
518
  * @since 0.6.0
520
519
  */
521
- 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) {
522
521
  const errorOptions = (format) => automaticWidth ? withAutomaticWidth(format, (width) => {
523
522
  maxWidth = width;
524
523
  }) : format;
@@ -527,7 +526,7 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
527
526
  const callOnError = (code, error) => onError(code, error);
528
527
  const callOnCompletion = (code) => onCompletion(code);
529
528
  if (!shellName) {
530
- const error = message`Missing shell name for completion.`;
529
+ const error = errors?.missingShell ?? message`Missing shell name for completion.`;
531
530
  const writeError = () => stderr(renderErrorMessage(error, errorOptions({
532
531
  messageFormatter,
533
532
  theme,
@@ -562,14 +561,15 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
562
561
  return result;
563
562
  }, async () => callOnError(1, error));
564
563
  }
565
- const shell = availableShells[shellName];
564
+ const shell = Object.hasOwn(availableShells, shellName) ? availableShells[shellName] : void 0;
566
565
  if (!shell) {
567
566
  const available = [];
568
567
  for (const name in availableShells) {
569
568
  if (available.length > 0) available.push(text(", "));
570
569
  available.push(value(name));
571
570
  }
572
- 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}.`;
573
573
  stderr(renderErrorMessage(error, errorOptions({
574
574
  messageFormatter,
575
575
  theme,
@@ -757,9 +757,76 @@ function collectActiveValueOptionNames(usage, commandPath, includeDirectAfterCom
757
757
  for (const name of optionNames.flag) names.delete(name);
758
758
  return names;
759
759
  }
760
+ function collectRootOptionNames(usage, names, rootLeadingNames) {
761
+ for (const term of usage) collectRootOptionNamesFromTerm(term, names, rootLeadingNames);
762
+ }
763
+ function collectRootOptionNamesFromTerm(term, names, rootLeadingNames) {
764
+ switch (term.type) {
765
+ case "option":
766
+ for (const name of term.names) {
767
+ if (!rootLeadingNames.has(name)) continue;
768
+ if (term.metavar != null) names.value.add(name);
769
+ else names.flag.add(name);
770
+ }
771
+ return;
772
+ case "optional":
773
+ case "multiple":
774
+ case "sequence":
775
+ collectRootOptionNames(term.terms, names, rootLeadingNames);
776
+ return;
777
+ case "exclusive":
778
+ for (const branch of term.terms) collectRootOptionNames(branch, names, rootLeadingNames);
779
+ return;
780
+ case "argument":
781
+ case "command":
782
+ case "literal":
783
+ case "passthrough":
784
+ case "ellipsis": return;
785
+ }
786
+ }
787
+ function collectActiveOptionNames(usage, commandPath, names, fromExclusive, includeDirectAfterCommandOptions) {
788
+ if (commandPath.length === 0) {
789
+ collectOptionNamesAtCurrentCommandDepth(usage, names, false);
790
+ return;
791
+ }
792
+ const [commandName, ...rest] = commandPath;
793
+ for (let i = 0; i < usage.length; i++) {
794
+ const term = usage[i];
795
+ if (term.type === "command" && term.name === commandName) {
796
+ const remainingUsage = usage.slice(i + 1);
797
+ if (rest.length === 0) collectOptionNamesAtCurrentCommandDepth(remainingUsage, names, !fromExclusive && includeDirectAfterCommandOptions);
798
+ else collectActiveOptionNames(remainingUsage, rest, names, fromExclusive, includeDirectAfterCommandOptions);
799
+ } else if (term.type === "exclusive") for (const branch of term.terms) collectActiveOptionNames(branch, commandPath, names, true, includeDirectAfterCommandOptions);
800
+ else if (term.type === "optional" || term.type === "multiple" || term.type === "sequence") collectActiveOptionNames(term.terms, commandPath, names, fromExclusive, includeDirectAfterCommandOptions);
801
+ }
802
+ }
760
803
  function isRootOptionToken(token, rootOptionSuggestions) {
761
804
  return token != null && rootOptionSuggestions.some((suggestion) => token === suggestion.text || token.startsWith(`${suggestion.text}=`));
762
805
  }
806
+ function collectOptionNamesAtCurrentCommandDepth(usage, names, afterMatchedCommand) {
807
+ for (const term of usage) if (collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand)) return;
808
+ }
809
+ function collectOptionNamesAtCurrentCommandDepthFromTerm(term, names, afterMatchedCommand) {
810
+ switch (term.type) {
811
+ case "command": return !afterMatchedCommand;
812
+ case "option":
813
+ if (term.metavar != null) for (const name of term.names) names.value.add(name);
814
+ else for (const name of term.names) names.flag.add(name);
815
+ return false;
816
+ case "optional":
817
+ case "multiple":
818
+ case "sequence":
819
+ collectOptionNamesAtCurrentCommandDepth(term.terms, names, afterMatchedCommand);
820
+ return false;
821
+ case "exclusive":
822
+ for (const branch of term.terms) collectOptionNamesAtCurrentCommandDepth(branch, names, false);
823
+ return false;
824
+ case "argument":
825
+ case "literal":
826
+ case "passthrough":
827
+ case "ellipsis": return false;
828
+ }
829
+ }
763
830
  function getRootMetaOptionSuggestions(helpOptionConfig, helpOptionNames, versionOptionConfig, versionOptionNames) {
764
831
  const suggestions = [];
765
832
  if (helpOptionConfig != null && !isSuggestionHidden(helpOptionConfig.hidden)) suggestions.push(...helpOptionNames.map((name) => ({
@@ -971,7 +1038,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
971
1038
  classified.shell,
972
1039
  ...classified.commandPath ?? [],
973
1040
  ...classified.args
974
- ], 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);
975
1042
  case "help": {
976
1043
  let helpGeneratorParser;
977
1044
  let docGeneratorParser;
@@ -4,7 +4,6 @@ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
4
4
  const require_dependency_runtime = require('./dependency-runtime.cjs');
5
5
  const require_internal_parser = require('./internal/parser.cjs');
6
6
  const require_annotation_state = require('./annotation-state.cjs');
7
- const require_short_option = require('./short-option.cjs');
8
7
  const require_execution_context = require('./execution-context.cjs');
9
8
  const require_phase2_seed = require('./phase2-seed.cjs');
10
9
  const require_dependency_metadata = require('./dependency-metadata.cjs');
@@ -479,7 +478,7 @@ function optional(parser) {
479
478
  require_internal_parser.defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
480
479
  require_internal_parser.defineInheritedAnnotationParser(optionalParser);
481
480
  require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
482
- return fluent(require_short_option.scopeParser(optionalParser, require_short_option.combinedOptionScope([parser])));
481
+ return fluent(optionalParser);
483
482
  }
484
483
  /**
485
484
  * Error type for structured error messages in {@link withDefault} default value callbacks.
@@ -730,7 +729,7 @@ function withDefault(parser, defaultValue, options) {
730
729
  require_internal_parser.defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
731
730
  require_internal_parser.defineInheritedAnnotationParser(withDefaultParser);
732
731
  require_internal_parser.defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
733
- return fluent(require_short_option.scopeParser(withDefaultParser, require_short_option.combinedOptionScope([parser])));
732
+ return fluent(withDefaultParser);
734
733
  }
735
734
  /**
736
735
  * Creates a parser that transforms the result value of another parser using
@@ -919,7 +918,7 @@ function map(parser, transform) {
919
918
  if (composed != null) mappedParser.dependencyMetadata = composed;
920
919
  }
921
920
  require_dependency_runtime.defineForwardedEffectfulSchedulingNodes(mappedParser, parser);
922
- return fluent(require_short_option.scopeParser(mappedParser, require_short_option.combinedOptionScope([parser])));
921
+ return fluent(mappedParser);
923
922
  }
924
923
  const deferredValueBrand = Symbol.for("@optique/core/deferredValue");
925
924
  /**
@@ -1715,7 +1714,7 @@ function multiple(parser, options = {}) {
1715
1714
  enumerable: false
1716
1715
  });
1717
1716
  }
1718
- return fluent(require_short_option.scopeParser(resultParser, require_short_option.combinedOptionScope([parser])));
1717
+ return fluent(resultParser);
1719
1718
  }
1720
1719
  /**
1721
1720
  * Creates a parser that requires the wrapped parser to consume at least one
@@ -1851,7 +1850,7 @@ function nonEmpty(parser) {
1851
1850
  enumerable: false
1852
1851
  });
1853
1852
  require_dependency_runtime.defineForwardedEffectfulSchedulingNodes(nonEmptyParser, parser);
1854
- return fluent(require_short_option.scopeParser(nonEmptyParser, require_short_option.combinedOptionScope([parser])));
1853
+ return fluent(nonEmptyParser);
1855
1854
  }
1856
1855
  const fluentParserMarker = Symbol.for("@optique/core/fluent");
1857
1856
  /**
package/dist/modifiers.js CHANGED
@@ -4,7 +4,6 @@ import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } fro
4
4
  import { defineForwardedEffectfulSchedulingNodes } from "./dependency-runtime.js";
5
5
  import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getOwnParseLanes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
6
6
  import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
7
- import { combinedOptionScope, scopeParser } from "./short-option.js";
8
7
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
9
8
  import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
10
9
  import { composeDependencyMetadata } from "./dependency-metadata.js";
@@ -479,7 +478,7 @@ function optional(parser) {
479
478
  defineParseLanes(optionalParser, adaptOptionalStyleParseLanes(parser));
480
479
  defineInheritedAnnotationParser(optionalParser);
481
480
  defineSourceBindingOnlyAnnotationCompletionParser(optionalParser);
482
- return fluent(scopeParser(optionalParser, combinedOptionScope([parser])));
481
+ return fluent(optionalParser);
483
482
  }
484
483
  /**
485
484
  * Error type for structured error messages in {@link withDefault} default value callbacks.
@@ -730,7 +729,7 @@ function withDefault(parser, defaultValue, options) {
730
729
  defineParseLanes(withDefaultParser, adaptOptionalStyleParseLanes(parser));
731
730
  defineInheritedAnnotationParser(withDefaultParser);
732
731
  defineSourceBindingOnlyAnnotationCompletionParser(withDefaultParser);
733
- return fluent(scopeParser(withDefaultParser, combinedOptionScope([parser])));
732
+ return fluent(withDefaultParser);
734
733
  }
735
734
  /**
736
735
  * Creates a parser that transforms the result value of another parser using
@@ -919,7 +918,7 @@ function map(parser, transform) {
919
918
  if (composed != null) mappedParser.dependencyMetadata = composed;
920
919
  }
921
920
  defineForwardedEffectfulSchedulingNodes(mappedParser, parser);
922
- return fluent(scopeParser(mappedParser, combinedOptionScope([parser])));
921
+ return fluent(mappedParser);
923
922
  }
924
923
  const deferredValueBrand = Symbol.for("@optique/core/deferredValue");
925
924
  /**
@@ -1715,7 +1714,7 @@ function multiple(parser, options = {}) {
1715
1714
  enumerable: false
1716
1715
  });
1717
1716
  }
1718
- return fluent(scopeParser(resultParser, combinedOptionScope([parser])));
1717
+ return fluent(resultParser);
1719
1718
  }
1720
1719
  /**
1721
1720
  * Creates a parser that requires the wrapped parser to consume at least one
@@ -1851,7 +1850,7 @@ function nonEmpty(parser) {
1851
1850
  enumerable: false
1852
1851
  });
1853
1852
  defineForwardedEffectfulSchedulingNodes(nonEmptyParser, parser);
1854
- return fluent(scopeParser(nonEmptyParser, combinedOptionScope([parser])));
1853
+ return fluent(nonEmptyParser);
1855
1854
  }
1856
1855
  const fluentParserMarker = Symbol.for("@optique/core/fluent");
1857
1856
  /**
@@ -6,14 +6,13 @@ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
6
6
  const require_internal_dependency = require('./internal/dependency.cjs');
7
7
  const require_dependency_runtime = require('./dependency-runtime.cjs');
8
8
  const require_annotation_state = require('./annotation-state.cjs');
9
- const require_usage_internals = require('./usage-internals.cjs');
10
- const require_short_option = require('./short-option.cjs');
11
9
  const require_command_alias = require('./internal/command-alias.cjs');
12
10
  const require_execution_context = require('./execution-context.cjs');
13
11
  const require_phase2_seed = require('./phase2-seed.cjs');
14
12
  const require_dependency_metadata = require('./dependency-metadata.cjs');
15
13
  const require_modifiers = require('./modifiers.cjs');
16
14
  const require_suggestion = require('./suggestion.cjs');
15
+ const require_usage_internals = require('./usage-internals.cjs');
17
16
  const require_valueparser = require('./valueparser.cjs');
18
17
 
19
18
  //#region src/primitives.ts
@@ -257,25 +256,11 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
257
256
  */
258
257
  function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
259
258
  if (hidden) return;
260
- if (context.optionsTerminated) return;
261
- const waitingForValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
262
- if (valueParser != null && !waitingForValue && !isTerminalValueState(context.state)) {
263
- const attached = require_short_option.attachedValuePrefix(context, prefix, optionNames$1);
264
- if (attached != null) {
265
- if (attached.value.length === 0 && optionNames$1.includes(prefix)) yield {
266
- kind: "literal",
267
- text: prefix,
268
- ...description != null ? { description } : {}
269
- };
270
- if (valueParser.suggest != null) for (const suggestion of getSuggestionsWithDependency(valueParser, attached.value, context.dependencyRegistry, context.exec)) yield require_short_option.prefixSuggestion(attached.head, suggestion);
271
- return;
272
- }
273
- }
274
259
  const equalsIndex = prefix.indexOf("=");
275
- if (equalsIndex >= 0 && !waitingForValue) {
260
+ if (equalsIndex >= 0) {
276
261
  const optionPart = prefix.slice(0, equalsIndex);
277
262
  const valuePart = prefix.slice(equalsIndex + 1);
278
- if (optionNames$1.includes(optionPart) && !/^-[^-]$/.test(optionPart)) {
263
+ if (optionNames$1.includes(optionPart)) {
279
264
  if (valueParser && valueParser.suggest) {
280
265
  const valueSuggestions = getSuggestionsWithDependency(valueParser, valuePart, context.dependencyRegistry, context.exec);
281
266
  for (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
@@ -356,25 +341,11 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
356
341
  */
357
342
  async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
358
343
  if (hidden) return;
359
- if (context.optionsTerminated) return;
360
- const waitingForValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
361
- if (valueParser != null && !waitingForValue && !isTerminalValueState(context.state)) {
362
- const attached = require_short_option.attachedValuePrefix(context, prefix, optionNames$1);
363
- if (attached != null) {
364
- if (attached.value.length === 0 && optionNames$1.includes(prefix)) yield {
365
- kind: "literal",
366
- text: prefix,
367
- ...description != null ? { description } : {}
368
- };
369
- if (valueParser.suggest != null) for await (const suggestion of getSuggestionsWithDependencyAsync(valueParser, attached.value, context.dependencyRegistry, context.exec)) yield require_short_option.prefixSuggestion(attached.head, suggestion);
370
- return;
371
- }
372
- }
373
344
  const equalsIndex = prefix.indexOf("=");
374
- if (equalsIndex >= 0 && !waitingForValue) {
345
+ if (equalsIndex >= 0) {
375
346
  const optionPart = prefix.slice(0, equalsIndex);
376
347
  const valuePart = prefix.slice(equalsIndex + 1);
377
- if (optionNames$1.includes(optionPart) && !/^-[^-]$/.test(optionPart)) {
348
+ if (optionNames$1.includes(optionPart)) {
378
349
  if (valueParser && valueParser.suggest) {
379
350
  const valueSuggestions = getSuggestionsWithDependencyAsync(valueParser, valuePart, context.dependencyRegistry, context.exec);
380
351
  for await (const suggestion of valueSuggestions) if (suggestion.kind === "literal") yield {
@@ -553,18 +524,10 @@ function option(...args) {
553
524
  };
554
525
  });
555
526
  }
556
- const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) => ({
557
- optionName: name,
558
- prefix: name.startsWith("/") ? `${name}:` : `${name}=`
559
- }));
560
- if (valueParser != null && optionNames$1.some((name) => /^-[^-]$/.test(name) && context.buffer[0].startsWith(name)) && !require_short_option.fullNameOwnsToken(context, context.buffer[0])) {
561
- for (const name of optionNames$1) if (/^-[^-]$/.test(name)) prefixes.push({
562
- optionName: name,
563
- prefix: name
564
- });
565
- }
566
- for (const { prefix, optionName: optionName$1 } of prefixes) {
527
+ const prefixes = optionNames$1.filter((name) => name.startsWith("--") || name.startsWith("/") || name.startsWith("-") && name.length > 2).map((name) => name.startsWith("/") ? `${name}:` : `${name}=`);
528
+ for (const prefix of prefixes) {
567
529
  if (!context.buffer[0].startsWith(prefix)) continue;
530
+ const optionName$1 = prefix.slice(0, -1);
568
531
  if (hasParsedOptionValue(context.state, valueParser)) return {
569
532
  success: false,
570
533
  consumed: 1,
@@ -605,7 +568,7 @@ function option(...args) {
605
568
  if (valueParser == null) {
606
569
  const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/));
607
570
  for (const shortOption of shortOptions) {
608
- if (!context.buffer[0].startsWith(shortOption) || require_short_option.fullNameOwnsToken(context, context.buffer[0])) continue;
571
+ if (!context.buffer[0].startsWith(shortOption)) continue;
609
572
  if (hasParsedOptionValue(context.state, valueParser)) return {
610
573
  success: false,
611
574
  consumed: 1,
@@ -894,7 +857,7 @@ function flag(...args) {
894
857
  }
895
858
  const shortOptions = optionNames$1.filter((name) => name.match(/^-[^-]$/));
896
859
  for (const shortOption of shortOptions) {
897
- if (!context.buffer[0].startsWith(shortOption) || require_short_option.fullNameOwnsToken(context, context.buffer[0])) continue;
860
+ if (!context.buffer[0].startsWith(shortOption)) continue;
898
861
  if (context.state?.success) return {
899
862
  success: false,
900
863
  consumed: 1,
@@ -1115,7 +1078,7 @@ function negatableFlag(names, options = {}) {
1115
1078
  }
1116
1079
  for (const shortOption of optionNames$1) {
1117
1080
  if (!shortOption.match(/^-[^-]$/)) continue;
1118
- if (!context.buffer[0].startsWith(shortOption) || require_short_option.fullNameOwnsToken(context, context.buffer[0])) continue;
1081
+ if (!context.buffer[0].startsWith(shortOption)) continue;
1119
1082
  return parseMatchedNegatableFlag(context, shortOption, valueByName.get(shortOption), [context.buffer[0].slice(0, 2)], 1, [`-${context.buffer[0].slice(2)}`, ...context.buffer.slice(1)], options);
1120
1083
  }
1121
1084
  const invalidOption = context.buffer[0];
@@ -1471,7 +1434,6 @@ function validateUniqueCommandNames(names) {
1471
1434
  function* suggestCommandSync(context, prefix, name, aliases, parser, options) {
1472
1435
  if (require_usage.isSuggestionHidden(options.hidden)) return;
1473
1436
  const state = normalizeCommandState(context.state);
1474
- if (state != null) context = require_short_option.withParserOptionScope(context, parser);
1475
1437
  if (state === void 0) {
1476
1438
  const description = options.brief ?? options.description;
1477
1439
  for (const commandName of [name, ...aliases]) if (commandName.startsWith(prefix)) yield {
@@ -1485,7 +1447,6 @@ function* suggestCommandSync(context, prefix, name, aliases, parser, options) {
1485
1447
  async function* suggestCommandAsync(context, prefix, name, aliases, parser, options) {
1486
1448
  if (require_usage.isSuggestionHidden(options.hidden)) return;
1487
1449
  const state = normalizeCommandState(context.state);
1488
- if (state != null) context = require_short_option.withParserOptionScope(context, parser);
1489
1450
  if (state === void 0) {
1490
1451
  const description = options.brief ?? options.description;
1491
1452
  for (const commandName of [name, ...aliases]) if (commandName.startsWith(prefix)) yield {
@@ -1526,8 +1487,6 @@ function command(name, parser, options = {}) {
1526
1487
  const isAsync = parser.mode === "async";
1527
1488
  const syncInnerParser = parser;
1528
1489
  const asyncInnerParser = parser;
1529
- const commandScope = require_short_option.selectableOptionScope(() => new Set(commandNames));
1530
- const enteredScope = require_short_option.combinedOptionScope([parser]);
1531
1490
  const result = {
1532
1491
  [Symbol.for("@optique/core/commandParser")]: true,
1533
1492
  mode: parser.mode,
@@ -1595,7 +1554,6 @@ function command(name, parser, options = {}) {
1595
1554
  ] : baseError
1596
1555
  };
1597
1556
  }
1598
- commandScope.select(context, enteredScope);
1599
1557
  return {
1600
1558
  success: true,
1601
1559
  next: {
@@ -1626,7 +1584,7 @@ function command(name, parser, options = {}) {
1626
1584
  }
1627
1585
  return parseResult;
1628
1586
  };
1629
- return require_mode_dispatch.dispatchByMode(parser.mode, () => wrapState(syncInnerParser.parse(require_execution_context.withChildContext(require_short_option.withParserOptionScope(context, parser), name, innerState, parser.usage))), async () => wrapState(await parser.parse(require_execution_context.withChildContext(require_short_option.withParserOptionScope(context, parser), name, innerState, parser.usage))));
1587
+ return require_mode_dispatch.dispatchByMode(parser.mode, () => wrapState(syncInnerParser.parse(require_execution_context.withChildContext(context, name, innerState, parser.usage))), async () => wrapState(await parser.parse(require_execution_context.withChildContext(context, name, innerState, parser.usage))));
1630
1588
  }
1631
1589
  return {
1632
1590
  success: false,
@@ -1776,9 +1734,7 @@ function command(name, parser, options = {}) {
1776
1734
  configurable: true,
1777
1735
  enumerable: false
1778
1736
  });
1779
- return require_modifiers.fluent(require_short_option.scopeParser(result, commandScope.source, (context) => {
1780
- if (normalizeCommandState(context.state) != null) commandScope.select(context, enteredScope);
1781
- }));
1737
+ return require_modifiers.fluent(result);
1782
1738
  }
1783
1739
  /**
1784
1740
  * Creates a parser that collects unrecognized options and passes them through.
@@ -104,7 +104,7 @@ interface OptionErrorOptions {
104
104
  /**
105
105
  * Creates a parser for various styles of command-line options that take an
106
106
  * argument value, such as `--option=value`, `-option=value`, `-o value`,
107
- * `-ovalue`, or `/option:value`.
107
+ * or `/option:value`.
108
108
  * @template M The execution mode of the parser.
109
109
  * @template T The type of value this parser produces.
110
110
  * @param args The {@link OptionName}s to parse, followed by
@@ -118,7 +118,7 @@ declare function option<M extends Mode, T>(...args: readonly [OptionName, ...rea
118
118
  /**
119
119
  * Creates a parser for various styles of command-line options that take an
120
120
  * argument value, such as `--option=value`, `-option=value`, `-o value`,
121
- * `-ovalue`, or `/option:value`.
121
+ * or `/option:value`.
122
122
  * @template M The execution mode of the parser.
123
123
  * @template T The type of value this parser produces.
124
124
  * @param args The {@link OptionName}s to parse, followed by
@@ -140,7 +140,7 @@ declare function option(...optionNames: readonly [OptionName, ...readonly Option
140
140
  /**
141
141
  * Creates a parser for various styles of command-line options that take an
142
142
  * argument value, such as `--option=value`, `-option=value`, `-o value`,
143
- * `-ovalue`, or `/option:value`.
143
+ * or `/option:value`.
144
144
  * @param args The {@link OptionName}s to parse, followed by
145
145
  * an optional {@link OptionOptions} object that allows you to
146
146
  * specify a description or other metadata.