@optique/core 0.7.10-dev.283 → 0.7.11
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/dist/primitives.cjs +10 -2
- package/dist/primitives.js +10 -2
- 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";
|
package/dist/primitives.cjs
CHANGED
|
@@ -665,8 +665,16 @@ function command(name, parser, options = {}) {
|
|
|
665
665
|
success: false,
|
|
666
666
|
error: options.errors?.notFound ?? require_message.message`Command ${require_message.optionName(name)} was not matched.`
|
|
667
667
|
};
|
|
668
|
-
else if (state[0] === "matched")
|
|
669
|
-
|
|
668
|
+
else if (state[0] === "matched") {
|
|
669
|
+
const parseResult = parser.parse({
|
|
670
|
+
buffer: [],
|
|
671
|
+
optionsTerminated: false,
|
|
672
|
+
usage: [],
|
|
673
|
+
state: parser.initialState
|
|
674
|
+
});
|
|
675
|
+
if (parseResult.success) return parser.complete(parseResult.next.state);
|
|
676
|
+
return parser.complete(parser.initialState);
|
|
677
|
+
} else if (state[0] === "parsing") return parser.complete(state[1]);
|
|
670
678
|
return {
|
|
671
679
|
success: false,
|
|
672
680
|
error: options.errors?.invalidState ?? require_message.message`Invalid command state during completion.`
|
package/dist/primitives.js
CHANGED
|
@@ -665,8 +665,16 @@ function command(name, parser, options = {}) {
|
|
|
665
665
|
success: false,
|
|
666
666
|
error: options.errors?.notFound ?? message`Command ${optionName(name)} was not matched.`
|
|
667
667
|
};
|
|
668
|
-
else if (state[0] === "matched")
|
|
669
|
-
|
|
668
|
+
else if (state[0] === "matched") {
|
|
669
|
+
const parseResult = parser.parse({
|
|
670
|
+
buffer: [],
|
|
671
|
+
optionsTerminated: false,
|
|
672
|
+
usage: [],
|
|
673
|
+
state: parser.initialState
|
|
674
|
+
});
|
|
675
|
+
if (parseResult.success) return parser.complete(parseResult.next.state);
|
|
676
|
+
return parser.complete(parser.initialState);
|
|
677
|
+
} else if (state[0] === "parsing") return parser.complete(state[1]);
|
|
670
678
|
return {
|
|
671
679
|
success: false,
|
|
672
680
|
error: options.errors?.invalidState ?? message`Invalid command state during completion.`
|