@optique/core 0.8.9-dev.349 → 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 +43 -0
- package/dist/facade.js +43 -0
- package/package.json +1 -1
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";
|