@optique/core 0.9.2 → 0.9.3
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 +53 -0
- package/dist/facade.js +53 -0
- package/dist/parser.cjs +3 -5
- package/dist/parser.js +3 -5
- package/package.json +1 -1
package/dist/facade.cjs
CHANGED
|
@@ -500,6 +500,59 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
500
500
|
else if (commandParsers.length === 2) helpGeneratorParser = require_constructs.longestMatch(commandParsers[0], commandParsers[1]);
|
|
501
501
|
else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
|
|
502
502
|
}
|
|
503
|
+
const reportInvalidHelpCommand = (validationError) => {
|
|
504
|
+
stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
|
|
505
|
+
colors,
|
|
506
|
+
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
507
|
+
expandCommands: true
|
|
508
|
+
}), 7)}`);
|
|
509
|
+
const errorMessage = require_message.formatMessage(validationError, {
|
|
510
|
+
colors,
|
|
511
|
+
quotes: !colors
|
|
512
|
+
});
|
|
513
|
+
stderr(`Error: ${errorMessage}`);
|
|
514
|
+
return onError(1);
|
|
515
|
+
};
|
|
516
|
+
if (classified.commands.length > 0) {
|
|
517
|
+
let validationContext = {
|
|
518
|
+
buffer: [...classified.commands],
|
|
519
|
+
optionsTerminated: false,
|
|
520
|
+
state: helpGeneratorParser.initialState,
|
|
521
|
+
usage: helpGeneratorParser.usage
|
|
522
|
+
};
|
|
523
|
+
const processStep = (stepResult) => {
|
|
524
|
+
if (!stepResult.success) return stepResult.error;
|
|
525
|
+
if (stepResult.consumed.length < 1) return require_message.message`Unexpected option or subcommand: ${require_message.optionName(validationContext.buffer[0])}.`;
|
|
526
|
+
validationContext = {
|
|
527
|
+
...validationContext,
|
|
528
|
+
buffer: stepResult.next.buffer,
|
|
529
|
+
optionsTerminated: stepResult.next.optionsTerminated,
|
|
530
|
+
state: stepResult.next.state,
|
|
531
|
+
usage: stepResult.next.usage ?? validationContext.usage
|
|
532
|
+
};
|
|
533
|
+
return validationContext.buffer.length > 0 ? "continue" : null;
|
|
534
|
+
};
|
|
535
|
+
let validationResult = "continue";
|
|
536
|
+
while (validationResult === "continue") {
|
|
537
|
+
const stepResult = helpGeneratorParser.parse(validationContext);
|
|
538
|
+
if (stepResult instanceof Promise) {
|
|
539
|
+
const asyncValidate = async (result$1) => {
|
|
540
|
+
let res = processStep(result$1);
|
|
541
|
+
while (res === "continue") {
|
|
542
|
+
const next = helpGeneratorParser.parse(validationContext);
|
|
543
|
+
const resolved = next instanceof Promise ? await next : next;
|
|
544
|
+
res = processStep(resolved);
|
|
545
|
+
}
|
|
546
|
+
if (res != null) return reportInvalidHelpCommand(res);
|
|
547
|
+
const docOrPromise$1 = require_parser.getDocPage(helpGeneratorParser, classified.commands);
|
|
548
|
+
return docOrPromise$1 instanceof Promise ? docOrPromise$1.then(displayHelp) : displayHelp(docOrPromise$1);
|
|
549
|
+
};
|
|
550
|
+
return stepResult.then(asyncValidate);
|
|
551
|
+
}
|
|
552
|
+
validationResult = processStep(stepResult);
|
|
553
|
+
}
|
|
554
|
+
if (validationResult != null) return reportInvalidHelpCommand(validationResult);
|
|
555
|
+
}
|
|
503
556
|
const displayHelp = (doc) => {
|
|
504
557
|
if (doc != null) {
|
|
505
558
|
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
|
@@ -500,6 +500,59 @@ function runParser(parser, programName, args, options = {}) {
|
|
|
500
500
|
else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
|
|
501
501
|
else helpGeneratorParser = longestMatch(...commandParsers);
|
|
502
502
|
}
|
|
503
|
+
const reportInvalidHelpCommand = (validationError) => {
|
|
504
|
+
stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
|
|
505
|
+
colors,
|
|
506
|
+
maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
|
|
507
|
+
expandCommands: true
|
|
508
|
+
}), 7)}`);
|
|
509
|
+
const errorMessage = formatMessage(validationError, {
|
|
510
|
+
colors,
|
|
511
|
+
quotes: !colors
|
|
512
|
+
});
|
|
513
|
+
stderr(`Error: ${errorMessage}`);
|
|
514
|
+
return onError(1);
|
|
515
|
+
};
|
|
516
|
+
if (classified.commands.length > 0) {
|
|
517
|
+
let validationContext = {
|
|
518
|
+
buffer: [...classified.commands],
|
|
519
|
+
optionsTerminated: false,
|
|
520
|
+
state: helpGeneratorParser.initialState,
|
|
521
|
+
usage: helpGeneratorParser.usage
|
|
522
|
+
};
|
|
523
|
+
const processStep = (stepResult) => {
|
|
524
|
+
if (!stepResult.success) return stepResult.error;
|
|
525
|
+
if (stepResult.consumed.length < 1) return message`Unexpected option or subcommand: ${optionName(validationContext.buffer[0])}.`;
|
|
526
|
+
validationContext = {
|
|
527
|
+
...validationContext,
|
|
528
|
+
buffer: stepResult.next.buffer,
|
|
529
|
+
optionsTerminated: stepResult.next.optionsTerminated,
|
|
530
|
+
state: stepResult.next.state,
|
|
531
|
+
usage: stepResult.next.usage ?? validationContext.usage
|
|
532
|
+
};
|
|
533
|
+
return validationContext.buffer.length > 0 ? "continue" : null;
|
|
534
|
+
};
|
|
535
|
+
let validationResult = "continue";
|
|
536
|
+
while (validationResult === "continue") {
|
|
537
|
+
const stepResult = helpGeneratorParser.parse(validationContext);
|
|
538
|
+
if (stepResult instanceof Promise) {
|
|
539
|
+
const asyncValidate = async (result$1) => {
|
|
540
|
+
let res = processStep(result$1);
|
|
541
|
+
while (res === "continue") {
|
|
542
|
+
const next = helpGeneratorParser.parse(validationContext);
|
|
543
|
+
const resolved = next instanceof Promise ? await next : next;
|
|
544
|
+
res = processStep(resolved);
|
|
545
|
+
}
|
|
546
|
+
if (res != null) return reportInvalidHelpCommand(res);
|
|
547
|
+
const docOrPromise$1 = getDocPage(helpGeneratorParser, classified.commands);
|
|
548
|
+
return docOrPromise$1 instanceof Promise ? docOrPromise$1.then(displayHelp) : displayHelp(docOrPromise$1);
|
|
549
|
+
};
|
|
550
|
+
return stepResult.then(asyncValidate);
|
|
551
|
+
}
|
|
552
|
+
validationResult = processStep(stepResult);
|
|
553
|
+
}
|
|
554
|
+
if (validationResult != null) return reportInvalidHelpCommand(validationResult);
|
|
555
|
+
}
|
|
503
556
|
const displayHelp = (doc) => {
|
|
504
557
|
if (doc != null) {
|
|
505
558
|
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
|
@@ -356,11 +356,9 @@ function buildDocPage(parser, context, args) {
|
|
|
356
356
|
const term = usage[i];
|
|
357
357
|
if (term.type === "exclusive") {
|
|
358
358
|
const found = findCommandInExclusive(term, arg);
|
|
359
|
-
if (found)
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
} else i++;
|
|
363
|
-
} else i++;
|
|
359
|
+
if (found) usage.splice(i, 1, ...found);
|
|
360
|
+
}
|
|
361
|
+
i++;
|
|
364
362
|
}
|
|
365
363
|
return {
|
|
366
364
|
usage,
|
package/dist/parser.js
CHANGED
|
@@ -356,11 +356,9 @@ function buildDocPage(parser, context, args) {
|
|
|
356
356
|
const term = usage[i];
|
|
357
357
|
if (term.type === "exclusive") {
|
|
358
358
|
const found = findCommandInExclusive(term, arg);
|
|
359
|
-
if (found)
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
} else i++;
|
|
363
|
-
} else i++;
|
|
359
|
+
if (found) usage.splice(i, 1, ...found);
|
|
360
|
+
}
|
|
361
|
+
i++;
|
|
364
362
|
}
|
|
365
363
|
return {
|
|
366
364
|
usage,
|