@optique/core 0.8.8 → 0.8.9

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
@@ -515,6 +515,49 @@ function run(parser, programName, args, options = {}) {
515
515
  else if (commandParsers.length === 2) helpGeneratorParser = require_constructs.longestMatch(commandParsers[0], commandParsers[1]);
516
516
  else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
517
517
  }
518
+ if (classified.commands.length > 0) {
519
+ let validationContext = {
520
+ buffer: [...classified.commands],
521
+ optionsTerminated: false,
522
+ state: helpGeneratorParser.initialState,
523
+ usage: helpGeneratorParser.usage
524
+ };
525
+ let commandsValid = true;
526
+ let validationError;
527
+ while (validationContext.buffer.length > 0) {
528
+ const stepResult = helpGeneratorParser.parse(validationContext);
529
+ if (!stepResult.success) {
530
+ commandsValid = false;
531
+ validationError = stepResult.error;
532
+ break;
533
+ }
534
+ if (stepResult.consumed.length < 1) {
535
+ commandsValid = false;
536
+ validationError = require_message.message`Unexpected option or subcommand: ${require_message.optionName(validationContext.buffer[0])}.`;
537
+ break;
538
+ }
539
+ validationContext = {
540
+ ...validationContext,
541
+ buffer: stepResult.next.buffer,
542
+ optionsTerminated: stepResult.next.optionsTerminated,
543
+ state: stepResult.next.state,
544
+ usage: stepResult.next.usage ?? validationContext.usage
545
+ };
546
+ }
547
+ if (!commandsValid && validationError != null) {
548
+ stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
549
+ colors,
550
+ maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
551
+ expandCommands: true
552
+ }), 7)}`);
553
+ const errorMessage = require_message.formatMessage(validationError, {
554
+ colors,
555
+ quotes: !colors
556
+ });
557
+ stderr(`Error: ${errorMessage}`);
558
+ return onError(1);
559
+ }
560
+ }
518
561
  const doc = require_parser.getDocPage(helpGeneratorParser, classified.commands);
519
562
  if (doc != null) {
520
563
  const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
package/dist/facade.js CHANGED
@@ -515,6 +515,49 @@ function run(parser, programName, args, options = {}) {
515
515
  else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
516
516
  else helpGeneratorParser = longestMatch(...commandParsers);
517
517
  }
518
+ if (classified.commands.length > 0) {
519
+ let validationContext = {
520
+ buffer: [...classified.commands],
521
+ optionsTerminated: false,
522
+ state: helpGeneratorParser.initialState,
523
+ usage: helpGeneratorParser.usage
524
+ };
525
+ let commandsValid = true;
526
+ let validationError;
527
+ while (validationContext.buffer.length > 0) {
528
+ const stepResult = helpGeneratorParser.parse(validationContext);
529
+ if (!stepResult.success) {
530
+ commandsValid = false;
531
+ validationError = stepResult.error;
532
+ break;
533
+ }
534
+ if (stepResult.consumed.length < 1) {
535
+ commandsValid = false;
536
+ validationError = message`Unexpected option or subcommand: ${optionName(validationContext.buffer[0])}.`;
537
+ break;
538
+ }
539
+ validationContext = {
540
+ ...validationContext,
541
+ buffer: stepResult.next.buffer,
542
+ optionsTerminated: stepResult.next.optionsTerminated,
543
+ state: stepResult.next.state,
544
+ usage: stepResult.next.usage ?? validationContext.usage
545
+ };
546
+ }
547
+ if (!commandsValid && validationError != null) {
548
+ stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
549
+ colors,
550
+ maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
551
+ expandCommands: true
552
+ }), 7)}`);
553
+ const errorMessage = formatMessage(validationError, {
554
+ colors,
555
+ quotes: !colors
556
+ });
557
+ stderr(`Error: ${errorMessage}`);
558
+ return onError(1);
559
+ }
560
+ }
518
561
  const doc = getDocPage(helpGeneratorParser, classified.commands);
519
562
  if (doc != null) {
520
563
  const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
package/dist/parser.cjs CHANGED
@@ -178,11 +178,9 @@ function getDocPage(parser, args = []) {
178
178
  const term = usage[i];
179
179
  if (term.type === "exclusive") {
180
180
  const found = findCommandInExclusive(term, arg);
181
- if (found) {
182
- usage.splice(i, 1, ...found);
183
- i += found.length;
184
- } else i++;
185
- } else i++;
181
+ if (found) usage.splice(i, 1, ...found);
182
+ }
183
+ i++;
186
184
  }
187
185
  return {
188
186
  usage,
package/dist/parser.js CHANGED
@@ -178,11 +178,9 @@ function getDocPage(parser, args = []) {
178
178
  const term = usage[i];
179
179
  if (term.type === "exclusive") {
180
180
  const found = findCommandInExclusive(term, arg);
181
- if (found) {
182
- usage.splice(i, 1, ...found);
183
- i += found.length;
184
- } else i++;
185
- } else i++;
181
+ if (found) usage.splice(i, 1, ...found);
182
+ }
183
+ i++;
186
184
  }
187
185
  return {
188
186
  usage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.8.8",
3
+ "version": "0.8.9",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",