Upgrade Ava to v4
This commit is contained in:
parent
9a40cc5274
commit
ce89f1b611
1153 changed files with 27264 additions and 95308 deletions
84
node_modules/yargs/build/lib/usage.js
generated
vendored
84
node_modules/yargs/build/lib/usage.js
generated
vendored
|
|
@ -1,9 +1,11 @@
|
|||
import { assertNotStrictEqual, } from './typings/common-types.js';
|
||||
import { objFilter } from './utils/obj-filter.js';
|
||||
import { YError } from './yerror.js';
|
||||
import setBlocking from './utils/set-blocking.js';
|
||||
export function usage(yargs, y18n, shim) {
|
||||
const __ = y18n.__;
|
||||
function isBoolean(fail) {
|
||||
return typeof fail === 'boolean';
|
||||
}
|
||||
export function usage(yargs, shim) {
|
||||
const __ = shim.y18n.__;
|
||||
const self = {};
|
||||
const fails = [];
|
||||
self.failFn = function failFn(f) {
|
||||
|
|
@ -22,10 +24,19 @@ export function usage(yargs, y18n, shim) {
|
|||
};
|
||||
let failureOutput = false;
|
||||
self.fail = function fail(msg, err) {
|
||||
const logger = yargs._getLoggerInstance();
|
||||
const logger = yargs.getInternalMethods().getLoggerInstance();
|
||||
if (fails.length) {
|
||||
for (let i = fails.length - 1; i >= 0; --i) {
|
||||
fails[i](msg, err, self);
|
||||
const fail = fails[i];
|
||||
if (isBoolean(fail)) {
|
||||
if (err)
|
||||
throw err;
|
||||
else if (msg)
|
||||
throw Error(msg);
|
||||
}
|
||||
else {
|
||||
fail(msg, err, self);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -49,7 +60,7 @@ export function usage(yargs, y18n, shim) {
|
|||
if (yargs.getExitProcess()) {
|
||||
return yargs.exit(1);
|
||||
}
|
||||
else if (yargs._hasParseCallback()) {
|
||||
else if (yargs.getInternalMethods().hasParseCallback()) {
|
||||
return yargs.exit(1, err);
|
||||
}
|
||||
else {
|
||||
|
|
@ -160,7 +171,7 @@ export function usage(yargs, y18n, shim) {
|
|||
if (!usageDisabled) {
|
||||
if (usages.length) {
|
||||
usages.forEach(usage => {
|
||||
ui.div(`${usage[0].replace(/\$0/g, base$0)}`);
|
||||
ui.div({ text: `${usage[0].replace(/\$0/g, base$0)}` });
|
||||
if (usage[1]) {
|
||||
ui.div({ text: `${usage[1]}`, padding: [1, 0, 0, 0] });
|
||||
}
|
||||
|
|
@ -178,17 +189,19 @@ export function usage(yargs, y18n, shim) {
|
|||
ui.div(`${u}`);
|
||||
}
|
||||
}
|
||||
if (commands.length) {
|
||||
if (commands.length > 1 || (commands.length === 1 && !commands[0][2])) {
|
||||
ui.div(__('Commands:'));
|
||||
const context = yargs.getContext();
|
||||
const context = yargs.getInternalMethods().getContext();
|
||||
const parentCommands = context.commands.length
|
||||
? `${context.commands.join(' ')} `
|
||||
: '';
|
||||
if (yargs.getParserConfiguration()['sort-commands'] === true) {
|
||||
if (yargs.getInternalMethods().getParserConfiguration()['sort-commands'] ===
|
||||
true) {
|
||||
commands = commands.sort((a, b) => a[0].localeCompare(b[0]));
|
||||
}
|
||||
const prefix = base$0 ? `${base$0} ` : '';
|
||||
commands.forEach(command => {
|
||||
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}`;
|
||||
const commandString = `${prefix}${parentCommands}${command[0].replace(/^\$0 ?/, '')}`;
|
||||
ui.span({
|
||||
text: commandString,
|
||||
padding: [0, 2, 0, 2],
|
||||
|
|
@ -235,10 +248,10 @@ export function usage(yargs, y18n, shim) {
|
|||
const normalizedKeys = groups[groupName]
|
||||
.filter(filterHiddenOptions)
|
||||
.map(key => {
|
||||
if (~aliasKeys.indexOf(key))
|
||||
if (aliasKeys.includes(key))
|
||||
return key;
|
||||
for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
|
||||
if (~(options.alias[aliasKey] || []).indexOf(key))
|
||||
if ((options.alias[aliasKey] || []).includes(key))
|
||||
return aliasKey;
|
||||
}
|
||||
return key;
|
||||
|
|
@ -255,7 +268,7 @@ export function usage(yargs, y18n, shim) {
|
|||
return sw;
|
||||
else {
|
||||
return ((/^[0-9]$/.test(sw)
|
||||
? ~options.boolean.indexOf(key)
|
||||
? options.boolean.includes(key)
|
||||
? '-'
|
||||
: '--'
|
||||
: sw.length > 1
|
||||
|
|
@ -293,19 +306,19 @@ export function usage(yargs, y18n, shim) {
|
|||
const kswitch = switches[key];
|
||||
let desc = descriptions[key] || '';
|
||||
let type = null;
|
||||
if (~desc.lastIndexOf(deferY18nLookupPrefix))
|
||||
if (desc.includes(deferY18nLookupPrefix))
|
||||
desc = __(desc.substring(deferY18nLookupPrefix.length));
|
||||
if (~options.boolean.indexOf(key))
|
||||
if (options.boolean.includes(key))
|
||||
type = `[${__('boolean')}]`;
|
||||
if (~options.count.indexOf(key))
|
||||
if (options.count.includes(key))
|
||||
type = `[${__('count')}]`;
|
||||
if (~options.string.indexOf(key))
|
||||
if (options.string.includes(key))
|
||||
type = `[${__('string')}]`;
|
||||
if (~options.normalize.indexOf(key))
|
||||
if (options.normalize.includes(key))
|
||||
type = `[${__('string')}]`;
|
||||
if (~options.array.indexOf(key))
|
||||
if (options.array.includes(key))
|
||||
type = `[${__('array')}]`;
|
||||
if (~options.number.indexOf(key))
|
||||
if (options.number.includes(key))
|
||||
type = `[${__('number')}]`;
|
||||
const deprecatedExtra = (deprecated) => typeof deprecated === 'string'
|
||||
? `[${__('deprecated: %s', deprecated)}]`
|
||||
|
|
@ -388,17 +401,17 @@ export function usage(yargs, y18n, shim) {
|
|||
self.describe(key, descriptions[alias]);
|
||||
if (alias in demandedOptions)
|
||||
yargs.demandOption(key, demandedOptions[alias]);
|
||||
if (~options.boolean.indexOf(alias))
|
||||
if (options.boolean.includes(alias))
|
||||
yargs.boolean(key);
|
||||
if (~options.count.indexOf(alias))
|
||||
if (options.count.includes(alias))
|
||||
yargs.count(key);
|
||||
if (~options.string.indexOf(alias))
|
||||
if (options.string.includes(alias))
|
||||
yargs.string(key);
|
||||
if (~options.normalize.indexOf(alias))
|
||||
if (options.normalize.includes(alias))
|
||||
yargs.normalize(key);
|
||||
if (~options.array.indexOf(alias))
|
||||
if (options.array.includes(alias))
|
||||
yargs.array(key);
|
||||
if (~options.number.indexOf(alias))
|
||||
if (options.number.includes(alias))
|
||||
yargs.number(key);
|
||||
});
|
||||
});
|
||||
|
|
@ -410,6 +423,9 @@ export function usage(yargs, y18n, shim) {
|
|||
self.clearCachedHelpMessage = function () {
|
||||
cachedHelpMessage = undefined;
|
||||
};
|
||||
self.hasCachedHelpMessage = function () {
|
||||
return !!cachedHelpMessage;
|
||||
};
|
||||
function addUngroupedKeys(keys, aliases, groups, defaultGroup) {
|
||||
let groupedKeys = [];
|
||||
let toCheck = null;
|
||||
|
|
@ -429,7 +445,7 @@ export function usage(yargs, y18n, shim) {
|
|||
yargs.parsed.argv[yargs.getOptions().showHiddenOpt]);
|
||||
}
|
||||
self.showHelp = (level) => {
|
||||
const logger = yargs._getLoggerInstance();
|
||||
const logger = yargs.getInternalMethods().getLoggerInstance();
|
||||
if (!level)
|
||||
level = 'error';
|
||||
const emit = typeof level === 'function' ? level : logger[level];
|
||||
|
|
@ -488,9 +504,12 @@ export function usage(yargs, y18n, shim) {
|
|||
self.version = ver => {
|
||||
version = ver;
|
||||
};
|
||||
self.showVersion = () => {
|
||||
const logger = yargs._getLoggerInstance();
|
||||
logger.log(version);
|
||||
self.showVersion = level => {
|
||||
const logger = yargs.getInternalMethods().getLoggerInstance();
|
||||
if (!level)
|
||||
level = 'error';
|
||||
const emit = typeof level === 'function' ? level : logger[level];
|
||||
emit(version);
|
||||
};
|
||||
self.reset = function reset(localLookup) {
|
||||
failMessage = null;
|
||||
|
|
@ -518,7 +537,8 @@ export function usage(yargs, y18n, shim) {
|
|||
};
|
||||
self.unfreeze = function unfreeze() {
|
||||
const frozen = frozens.pop();
|
||||
assertNotStrictEqual(frozen, undefined, shim);
|
||||
if (!frozen)
|
||||
return;
|
||||
({
|
||||
failMessage,
|
||||
failureOutput,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue