@optique/core 1.0.0-dev.479 → 1.0.0-dev.487

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
@@ -615,6 +615,35 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
615
615
  stderr(`Error: ${errorMessage}`);
616
616
  return onError(1);
617
617
  };
618
+ const displayHelp = (doc) => {
619
+ if (doc != null) {
620
+ const isMetaCommandHelp = requestedCommand != null && completionCommandNames.includes(requestedCommand) || requestedCommand != null && helpCommandNames.includes(requestedCommand) || requestedCommand != null && versionCommandNames.includes(requestedCommand);
621
+ const isSubcommandHelp = classified.commands.length > 0;
622
+ const isTopLevel = !isSubcommandHelp;
623
+ const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
624
+ const augmentedDoc = {
625
+ ...doc,
626
+ brief: shouldOverride ? brief ?? doc.brief : doc.brief,
627
+ description: shouldOverride ? description ?? doc.description : doc.description,
628
+ examples: isTopLevel && !isMetaCommandHelp ? examples ?? doc.examples : void 0,
629
+ author: isTopLevel && !isMetaCommandHelp ? author ?? doc.author : void 0,
630
+ bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
631
+ footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
632
+ };
633
+ stdout(require_doc.formatDocPage(programName, augmentedDoc, {
634
+ colors,
635
+ maxWidth,
636
+ showDefault,
637
+ showChoices,
638
+ sectionOrder
639
+ }));
640
+ }
641
+ try {
642
+ return onHelp(0);
643
+ } catch {
644
+ return onHelp();
645
+ }
646
+ };
618
647
  if (classified.commands.length > 0) {
619
648
  let validationContext = {
620
649
  buffer: [...classified.commands],
@@ -655,35 +684,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
655
684
  }
656
685
  if (validationResult != null) return reportInvalidHelpCommand(validationResult);
657
686
  }
658
- const displayHelp = (doc) => {
659
- if (doc != null) {
660
- const isMetaCommandHelp = requestedCommand != null && completionCommandNames.includes(requestedCommand) || requestedCommand != null && helpCommandNames.includes(requestedCommand) || requestedCommand != null && versionCommandNames.includes(requestedCommand);
661
- const isSubcommandHelp = classified.commands.length > 0;
662
- const isTopLevel = !isSubcommandHelp;
663
- const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
664
- const augmentedDoc = {
665
- ...doc,
666
- brief: shouldOverride ? brief ?? doc.brief : doc.brief,
667
- description: shouldOverride ? description ?? doc.description : doc.description,
668
- examples: isTopLevel && !isMetaCommandHelp ? examples ?? doc.examples : void 0,
669
- author: isTopLevel && !isMetaCommandHelp ? author ?? doc.author : void 0,
670
- bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
671
- footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
672
- };
673
- stdout(require_doc.formatDocPage(programName, augmentedDoc, {
674
- colors,
675
- maxWidth,
676
- showDefault,
677
- showChoices,
678
- sectionOrder
679
- }));
680
- }
681
- try {
682
- return onHelp(0);
683
- } catch {
684
- return onHelp();
685
- }
686
- };
687
687
  const docOrPromise = require_parser.getDocPage(helpGeneratorParser, classified.commands);
688
688
  if (docOrPromise instanceof Promise) return docOrPromise.then(displayHelp);
689
689
  return displayHelp(docOrPromise);
package/dist/facade.js CHANGED
@@ -615,6 +615,35 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
615
615
  stderr(`Error: ${errorMessage}`);
616
616
  return onError(1);
617
617
  };
618
+ const displayHelp = (doc) => {
619
+ if (doc != null) {
620
+ const isMetaCommandHelp = requestedCommand != null && completionCommandNames.includes(requestedCommand) || requestedCommand != null && helpCommandNames.includes(requestedCommand) || requestedCommand != null && versionCommandNames.includes(requestedCommand);
621
+ const isSubcommandHelp = classified.commands.length > 0;
622
+ const isTopLevel = !isSubcommandHelp;
623
+ const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
624
+ const augmentedDoc = {
625
+ ...doc,
626
+ brief: shouldOverride ? brief ?? doc.brief : doc.brief,
627
+ description: shouldOverride ? description ?? doc.description : doc.description,
628
+ examples: isTopLevel && !isMetaCommandHelp ? examples ?? doc.examples : void 0,
629
+ author: isTopLevel && !isMetaCommandHelp ? author ?? doc.author : void 0,
630
+ bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
631
+ footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
632
+ };
633
+ stdout(formatDocPage(programName, augmentedDoc, {
634
+ colors,
635
+ maxWidth,
636
+ showDefault,
637
+ showChoices,
638
+ sectionOrder
639
+ }));
640
+ }
641
+ try {
642
+ return onHelp(0);
643
+ } catch {
644
+ return onHelp();
645
+ }
646
+ };
618
647
  if (classified.commands.length > 0) {
619
648
  let validationContext = {
620
649
  buffer: [...classified.commands],
@@ -655,35 +684,6 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
655
684
  }
656
685
  if (validationResult != null) return reportInvalidHelpCommand(validationResult);
657
686
  }
658
- const displayHelp = (doc) => {
659
- if (doc != null) {
660
- const isMetaCommandHelp = requestedCommand != null && completionCommandNames.includes(requestedCommand) || requestedCommand != null && helpCommandNames.includes(requestedCommand) || requestedCommand != null && versionCommandNames.includes(requestedCommand);
661
- const isSubcommandHelp = classified.commands.length > 0;
662
- const isTopLevel = !isSubcommandHelp;
663
- const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
664
- const augmentedDoc = {
665
- ...doc,
666
- brief: shouldOverride ? brief ?? doc.brief : doc.brief,
667
- description: shouldOverride ? description ?? doc.description : doc.description,
668
- examples: isTopLevel && !isMetaCommandHelp ? examples ?? doc.examples : void 0,
669
- author: isTopLevel && !isMetaCommandHelp ? author ?? doc.author : void 0,
670
- bugs: isTopLevel && !isMetaCommandHelp ? bugs ?? doc.bugs : void 0,
671
- footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
672
- };
673
- stdout(formatDocPage(programName, augmentedDoc, {
674
- colors,
675
- maxWidth,
676
- showDefault,
677
- showChoices,
678
- sectionOrder
679
- }));
680
- }
681
- try {
682
- return onHelp(0);
683
- } catch {
684
- return onHelp();
685
- }
686
- };
687
687
  const docOrPromise = getDocPage(helpGeneratorParser, classified.commands);
688
688
  if (docOrPromise instanceof Promise) return docOrPromise.then(displayHelp);
689
689
  return displayHelp(docOrPromise);
@@ -495,7 +495,6 @@ function multiple(parser, options = {}) {
495
495
  });
496
496
  },
497
497
  suggest(context, prefix) {
498
- const innerState = context.state.length > 0 ? context.state.at(-1) : parser.initialState;
499
498
  const selectedValues = /* @__PURE__ */ new Set();
500
499
  for (const s of context.state) {
501
500
  const completed = syncParser.complete(s);
@@ -511,12 +510,12 @@ function multiple(parser, options = {}) {
511
510
  return require_mode_dispatch.dispatchIterableByMode(parser.$mode, function* () {
512
511
  for (const s of syncParser.suggest({
513
512
  ...context,
514
- state: innerState
513
+ state: parser.initialState
515
514
  }, prefix)) if (shouldInclude(s)) yield s;
516
515
  }, async function* () {
517
516
  const suggestions = parser.suggest({
518
517
  ...context,
519
- state: innerState
518
+ state: parser.initialState
520
519
  }, prefix);
521
520
  for await (const s of suggestions) if (shouldInclude(s)) yield s;
522
521
  });
package/dist/modifiers.js CHANGED
@@ -495,7 +495,6 @@ function multiple(parser, options = {}) {
495
495
  });
496
496
  },
497
497
  suggest(context, prefix) {
498
- const innerState = context.state.length > 0 ? context.state.at(-1) : parser.initialState;
499
498
  const selectedValues = /* @__PURE__ */ new Set();
500
499
  for (const s of context.state) {
501
500
  const completed = syncParser.complete(s);
@@ -511,12 +510,12 @@ function multiple(parser, options = {}) {
511
510
  return dispatchIterableByMode(parser.$mode, function* () {
512
511
  for (const s of syncParser.suggest({
513
512
  ...context,
514
- state: innerState
513
+ state: parser.initialState
515
514
  }, prefix)) if (shouldInclude(s)) yield s;
516
515
  }, async function* () {
517
516
  const suggestions = parser.suggest({
518
517
  ...context,
519
- state: innerState
518
+ state: parser.initialState
520
519
  }, prefix);
521
520
  for await (const s of suggestions) if (shouldInclude(s)) yield s;
522
521
  });
@@ -1,5 +1,6 @@
1
1
  const require_message = require('./message.cjs');
2
2
  const require_dependency = require('./dependency.cjs');
3
+ const require_mode_dispatch = require('./mode-dispatch.cjs');
3
4
  const require_usage = require('./usage.cjs');
4
5
  const require_suggestion = require('./suggestion.cjs');
5
6
  const require_usage_internals = require('./usage-internals.cjs');
@@ -163,7 +164,8 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, context, prefix)
163
164
  }
164
165
  }
165
166
  } else {
166
- if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/")) {
167
+ const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
168
+ if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
167
169
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
168
170
  if (prefix === "-" && optionName$1.length !== 2) continue;
169
171
  yield {
@@ -244,7 +246,8 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, context,
244
246
  }
245
247
  }
246
248
  } else {
247
- if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/")) {
249
+ const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
250
+ if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
248
251
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
249
252
  if (prefix === "-" && optionName$1.length !== 2) continue;
250
253
  yield {
@@ -833,6 +836,7 @@ function argument(valueParser, options = {}) {
833
836
  };
834
837
  },
835
838
  suggest(context, prefix) {
839
+ if (context.state != null) return require_mode_dispatch.dispatchIterableByMode(valueParser.$mode, function* () {}, async function* () {});
836
840
  if (isAsync) return suggestArgumentAsync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
837
841
  return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
838
842
  },
@@ -1,5 +1,6 @@
1
1
  import { message, metavar, optionName, optionNames, text, valueSet } from "./message.js";
2
2
  import { createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependencyId, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, suggestWithDependency } from "./dependency.js";
3
+ import { dispatchIterableByMode } from "./mode-dispatch.js";
3
4
  import { extractOptionNames, isDocHidden, isSuggestionHidden } from "./usage.js";
4
5
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, createSuggestionMessage, findSimilar } from "./suggestion.js";
5
6
  import { extractLeadingCommandNames } from "./usage-internals.js";
@@ -163,7 +164,8 @@ function* suggestOptionSync(optionNames$1, valueParser, hidden, context, prefix)
163
164
  }
164
165
  }
165
166
  } else {
166
- if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/")) {
167
+ const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
168
+ if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
167
169
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
168
170
  if (prefix === "-" && optionName$1.length !== 2) continue;
169
171
  yield {
@@ -244,7 +246,8 @@ async function* suggestOptionAsync(optionNames$1, valueParser, hidden, context,
244
246
  }
245
247
  }
246
248
  } else {
247
- if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/")) {
249
+ const expectingValue = context.buffer.length > 0 && optionNames$1.includes(context.buffer[context.buffer.length - 1]);
250
+ if (!expectingValue && (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/"))) {
248
251
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
249
252
  if (prefix === "-" && optionName$1.length !== 2) continue;
250
253
  yield {
@@ -833,6 +836,7 @@ function argument(valueParser, options = {}) {
833
836
  };
834
837
  },
835
838
  suggest(context, prefix) {
839
+ if (context.state != null) return dispatchIterableByMode(valueParser.$mode, function* () {}, async function* () {});
836
840
  if (isAsync) return suggestArgumentAsync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
837
841
  return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry);
838
842
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.479+a619f71b",
3
+ "version": "1.0.0-dev.487+3c38bb65",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",