@black-flag/extensions
Version:
A collection of set-theoretic declarative-first APIs for yargs and Black Flag
77 lines (76 loc) • 3.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BfeErrorMessage = void 0;
require("core-js/modules/es.iterator.constructor.js");
require("core-js/modules/es.iterator.reduce.js");
var _util = require("@black-flag/core/util");
var _symbols = require("./symbols.js");
const BfeErrorMessage = exports.BfeErrorMessage = {
..._util.BfErrorMessage,
FalsyCommandExport() {
return 'supposed command argument unexpectedly resolved to a falsy value';
},
CommandHandlerNotAFunction() {
return 'resolved command object unexpectedly returned a non-function handler';
},
ReferencedNonExistentOption(referrerName, doesNotExistName) {
return `option "${referrerName}" illegally references the non-existent option "${doesNotExistName}" in its configuration`;
},
DuplicateOptionName(name) {
return `one or more options of the currently executing command are attempting to register a duplicate name, expanded name, alias, or expanded alias: "${name}". Option names, their aliases, and all potential expansions must be unique.`;
},
IllegalHandlerInvocation() {
return 'withHandlerExtensions::handler was invoked too soon: options analysis unavailable';
},
MetadataInvariantViolated(afflictedKey) {
return `an impossible state was detected while analyzing configuration for key: ${afflictedKey}`;
},
UnexpectedlyFalsyDetailedArguments() {
return 'a Black Flag instance is somehow missing its detailed parse result. This is likely the result of an incompatibility between Black Flag and whatever version of Yargs is installed. Please report this!';
},
UnexpectedValueFromInternalYargsMethod() {
return 'a Black Flag instance is returning something unexpected from its "getParserConfiguration" internal method. This is likely the result of an incompatibility between Black Flag and whatever version of Yargs is installed. Please report this!';
},
RequiresViolation(requirer, missingRequiredKeyValues) {
return `the following missing arguments must be given alongside "${requirer}":${keyValuesToString(missingRequiredKeyValues)}`;
},
ConflictsViolation(conflicter, seenConflictingKeyValues) {
return `the following arguments cannot be given alongside "${conflicter}":${keyValuesToString(seenConflictingKeyValues)}`;
},
ImpliesViolation(implier, seenConflictingKeyValues) {
return `the following arguments as given conflict with the implications of "${implier}":${keyValuesToString(seenConflictingKeyValues)}`;
},
DemandIfViolation(demanded, demander) {
return `the argument "${demanded}" must be given whenever the following is given: ${keyValuesToString([demander])}`;
},
DemandOrViolation(demanded) {
return `at least one of the following arguments must be given:${keyValuesToString(demanded)}`;
},
DemandGenericXorViolation(demanded) {
return `exactly one of the following arguments must be given:${keyValuesToString(demanded)}`;
},
DemandSpecificXorViolation(firstArgument, secondArgument) {
return BfeErrorMessage.DemandGenericXorViolation([firstArgument, secondArgument]);
},
CheckFailed(currentArgument) {
return `check failed for argument "${currentArgument}"`;
}
};
function keyValuesToString(keyValueEntries) {
return keyValueEntries.reduce((str, keyValueEntry) => {
return `${str}\n ➜ ${keyValueToString(keyValueEntry)}`;
}, '');
}
function keyValueToString(keyValueEntry) {
const [key, value] = keyValueEntry;
const stringifiedValue = (() => {
try {
return JSON.stringify(value);
} catch {
return String(value);
}
})();
return value === _symbols.$exists ? key : `${key} == ${stringifiedValue}`;
}