chore: update deps
This commit is contained in:
62
node_modules/yargs/build/lib/argsert.js
generated
vendored
62
node_modules/yargs/build/lib/argsert.js
generated
vendored
@ -1,62 +0,0 @@
|
||||
import { YError } from './yerror.js';
|
||||
import { parseCommand } from './parse-command.js';
|
||||
const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth'];
|
||||
export function argsert(arg1, arg2, arg3) {
|
||||
function parseArgs() {
|
||||
return typeof arg1 === 'object'
|
||||
? [{ demanded: [], optional: [] }, arg1, arg2]
|
||||
: [
|
||||
parseCommand(`cmd ${arg1}`),
|
||||
arg2,
|
||||
arg3,
|
||||
];
|
||||
}
|
||||
try {
|
||||
let position = 0;
|
||||
const [parsed, callerArguments, _length] = parseArgs();
|
||||
const args = [].slice.call(callerArguments);
|
||||
while (args.length && args[args.length - 1] === undefined)
|
||||
args.pop();
|
||||
const length = _length || args.length;
|
||||
if (length < parsed.demanded.length) {
|
||||
throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`);
|
||||
}
|
||||
const totalCommands = parsed.demanded.length + parsed.optional.length;
|
||||
if (length > totalCommands) {
|
||||
throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`);
|
||||
}
|
||||
parsed.demanded.forEach(demanded => {
|
||||
const arg = args.shift();
|
||||
const observedType = guessType(arg);
|
||||
const matchingTypes = demanded.cmd.filter(type => type === observedType || type === '*');
|
||||
if (matchingTypes.length === 0)
|
||||
argumentTypeError(observedType, demanded.cmd, position);
|
||||
position += 1;
|
||||
});
|
||||
parsed.optional.forEach(optional => {
|
||||
if (args.length === 0)
|
||||
return;
|
||||
const arg = args.shift();
|
||||
const observedType = guessType(arg);
|
||||
const matchingTypes = optional.cmd.filter(type => type === observedType || type === '*');
|
||||
if (matchingTypes.length === 0)
|
||||
argumentTypeError(observedType, optional.cmd, position);
|
||||
position += 1;
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(err.stack);
|
||||
}
|
||||
}
|
||||
function guessType(arg) {
|
||||
if (Array.isArray(arg)) {
|
||||
return 'array';
|
||||
}
|
||||
else if (arg === null) {
|
||||
return 'null';
|
||||
}
|
||||
return typeof arg;
|
||||
}
|
||||
function argumentTypeError(observedType, allowedTypes, position) {
|
||||
throw new YError(`Invalid ${positionName[position] || 'manyith'} argument. Expected ${allowedTypes.join(' or ')} but received ${observedType}.`);
|
||||
}
|
449
node_modules/yargs/build/lib/command.js
generated
vendored
449
node_modules/yargs/build/lib/command.js
generated
vendored
@ -1,449 +0,0 @@
|
||||
import { assertNotStrictEqual, } from './typings/common-types.js';
|
||||
import { isPromise } from './utils/is-promise.js';
|
||||
import { applyMiddleware, commandMiddlewareFactory, } from './middleware.js';
|
||||
import { parseCommand } from './parse-command.js';
|
||||
import { isYargsInstance, } from './yargs-factory.js';
|
||||
import { maybeAsyncResult } from './utils/maybe-async-result.js';
|
||||
import whichModule from './utils/which-module.js';
|
||||
const DEFAULT_MARKER = /(^\*)|(^\$0)/;
|
||||
export class CommandInstance {
|
||||
constructor(usage, validation, globalMiddleware, shim) {
|
||||
this.requireCache = new Set();
|
||||
this.handlers = {};
|
||||
this.aliasMap = {};
|
||||
this.frozens = [];
|
||||
this.shim = shim;
|
||||
this.usage = usage;
|
||||
this.globalMiddleware = globalMiddleware;
|
||||
this.validation = validation;
|
||||
}
|
||||
addDirectory(dir, req, callerFile, opts) {
|
||||
opts = opts || {};
|
||||
if (typeof opts.recurse !== 'boolean')
|
||||
opts.recurse = false;
|
||||
if (!Array.isArray(opts.extensions))
|
||||
opts.extensions = ['js'];
|
||||
const parentVisit = typeof opts.visit === 'function' ? opts.visit : (o) => o;
|
||||
opts.visit = (obj, joined, filename) => {
|
||||
const visited = parentVisit(obj, joined, filename);
|
||||
if (visited) {
|
||||
if (this.requireCache.has(joined))
|
||||
return visited;
|
||||
else
|
||||
this.requireCache.add(joined);
|
||||
this.addHandler(visited);
|
||||
}
|
||||
return visited;
|
||||
};
|
||||
this.shim.requireDirectory({ require: req, filename: callerFile }, dir, opts);
|
||||
}
|
||||
addHandler(cmd, description, builder, handler, commandMiddleware, deprecated) {
|
||||
let aliases = [];
|
||||
const middlewares = commandMiddlewareFactory(commandMiddleware);
|
||||
handler = handler || (() => { });
|
||||
if (Array.isArray(cmd)) {
|
||||
if (isCommandAndAliases(cmd)) {
|
||||
[cmd, ...aliases] = cmd;
|
||||
}
|
||||
else {
|
||||
for (const command of cmd) {
|
||||
this.addHandler(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isCommandHandlerDefinition(cmd)) {
|
||||
let command = Array.isArray(cmd.command) || typeof cmd.command === 'string'
|
||||
? cmd.command
|
||||
: this.moduleName(cmd);
|
||||
if (cmd.aliases)
|
||||
command = [].concat(command).concat(cmd.aliases);
|
||||
this.addHandler(command, this.extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares, cmd.deprecated);
|
||||
return;
|
||||
}
|
||||
else if (isCommandBuilderDefinition(builder)) {
|
||||
this.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated);
|
||||
return;
|
||||
}
|
||||
if (typeof cmd === 'string') {
|
||||
const parsedCommand = parseCommand(cmd);
|
||||
aliases = aliases.map(alias => parseCommand(alias).cmd);
|
||||
let isDefault = false;
|
||||
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => {
|
||||
if (DEFAULT_MARKER.test(c)) {
|
||||
isDefault = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (parsedAliases.length === 0 && isDefault)
|
||||
parsedAliases.push('$0');
|
||||
if (isDefault) {
|
||||
parsedCommand.cmd = parsedAliases[0];
|
||||
aliases = parsedAliases.slice(1);
|
||||
cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd);
|
||||
}
|
||||
aliases.forEach(alias => {
|
||||
this.aliasMap[alias] = parsedCommand.cmd;
|
||||
});
|
||||
if (description !== false) {
|
||||
this.usage.command(cmd, description, isDefault, aliases, deprecated);
|
||||
}
|
||||
this.handlers[parsedCommand.cmd] = {
|
||||
original: cmd,
|
||||
description,
|
||||
handler,
|
||||
builder: builder || {},
|
||||
middlewares,
|
||||
deprecated,
|
||||
demanded: parsedCommand.demanded,
|
||||
optional: parsedCommand.optional,
|
||||
};
|
||||
if (isDefault)
|
||||
this.defaultCommand = this.handlers[parsedCommand.cmd];
|
||||
}
|
||||
}
|
||||
getCommandHandlers() {
|
||||
return this.handlers;
|
||||
}
|
||||
getCommands() {
|
||||
return Object.keys(this.handlers).concat(Object.keys(this.aliasMap));
|
||||
}
|
||||
hasDefaultCommand() {
|
||||
return !!this.defaultCommand;
|
||||
}
|
||||
runCommand(command, yargs, parsed, commandIndex, helpOnly, helpOrVersionSet) {
|
||||
const commandHandler = this.handlers[command] ||
|
||||
this.handlers[this.aliasMap[command]] ||
|
||||
this.defaultCommand;
|
||||
const currentContext = yargs.getInternalMethods().getContext();
|
||||
const parentCommands = currentContext.commands.slice();
|
||||
const isDefaultCommand = !command;
|
||||
if (command) {
|
||||
currentContext.commands.push(command);
|
||||
currentContext.fullCommands.push(commandHandler.original);
|
||||
}
|
||||
const builderResult = this.applyBuilderUpdateUsageAndParse(isDefaultCommand, commandHandler, yargs, parsed.aliases, parentCommands, commandIndex, helpOnly, helpOrVersionSet);
|
||||
return isPromise(builderResult)
|
||||
? builderResult.then(result => this.applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, result.innerArgv, currentContext, helpOnly, result.aliases, yargs))
|
||||
: this.applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, builderResult.innerArgv, currentContext, helpOnly, builderResult.aliases, yargs);
|
||||
}
|
||||
applyBuilderUpdateUsageAndParse(isDefaultCommand, commandHandler, yargs, aliases, parentCommands, commandIndex, helpOnly, helpOrVersionSet) {
|
||||
const builder = commandHandler.builder;
|
||||
let innerYargs = yargs;
|
||||
if (isCommandBuilderCallback(builder)) {
|
||||
yargs.getInternalMethods().getUsageInstance().freeze();
|
||||
const builderOutput = builder(yargs.getInternalMethods().reset(aliases), helpOrVersionSet);
|
||||
if (isPromise(builderOutput)) {
|
||||
return builderOutput.then(output => {
|
||||
innerYargs = isYargsInstance(output) ? output : yargs;
|
||||
return this.parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly);
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (isCommandBuilderOptionDefinitions(builder)) {
|
||||
yargs.getInternalMethods().getUsageInstance().freeze();
|
||||
innerYargs = yargs.getInternalMethods().reset(aliases);
|
||||
Object.keys(commandHandler.builder).forEach(key => {
|
||||
innerYargs.option(key, builder[key]);
|
||||
});
|
||||
}
|
||||
return this.parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly);
|
||||
}
|
||||
parseAndUpdateUsage(isDefaultCommand, commandHandler, innerYargs, parentCommands, commandIndex, helpOnly) {
|
||||
if (isDefaultCommand)
|
||||
innerYargs.getInternalMethods().getUsageInstance().unfreeze(true);
|
||||
if (this.shouldUpdateUsage(innerYargs)) {
|
||||
innerYargs
|
||||
.getInternalMethods()
|
||||
.getUsageInstance()
|
||||
.usage(this.usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description);
|
||||
}
|
||||
const innerArgv = innerYargs
|
||||
.getInternalMethods()
|
||||
.runYargsParserAndExecuteCommands(null, undefined, true, commandIndex, helpOnly);
|
||||
return isPromise(innerArgv)
|
||||
? innerArgv.then(argv => ({
|
||||
aliases: innerYargs.parsed.aliases,
|
||||
innerArgv: argv,
|
||||
}))
|
||||
: {
|
||||
aliases: innerYargs.parsed.aliases,
|
||||
innerArgv: innerArgv,
|
||||
};
|
||||
}
|
||||
shouldUpdateUsage(yargs) {
|
||||
return (!yargs.getInternalMethods().getUsageInstance().getUsageDisabled() &&
|
||||
yargs.getInternalMethods().getUsageInstance().getUsage().length === 0);
|
||||
}
|
||||
usageFromParentCommandsCommandHandler(parentCommands, commandHandler) {
|
||||
const c = DEFAULT_MARKER.test(commandHandler.original)
|
||||
? commandHandler.original.replace(DEFAULT_MARKER, '').trim()
|
||||
: commandHandler.original;
|
||||
const pc = parentCommands.filter(c => {
|
||||
return !DEFAULT_MARKER.test(c);
|
||||
});
|
||||
pc.push(c);
|
||||
return `$0 ${pc.join(' ')}`;
|
||||
}
|
||||
handleValidationAndGetResult(isDefaultCommand, commandHandler, innerArgv, currentContext, aliases, yargs, middlewares, positionalMap) {
|
||||
if (!yargs.getInternalMethods().getHasOutput()) {
|
||||
const validation = yargs
|
||||
.getInternalMethods()
|
||||
.runValidation(aliases, positionalMap, yargs.parsed.error, isDefaultCommand);
|
||||
innerArgv = maybeAsyncResult(innerArgv, result => {
|
||||
validation(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
if (commandHandler.handler && !yargs.getInternalMethods().getHasOutput()) {
|
||||
yargs.getInternalMethods().setHasOutput();
|
||||
const populateDoubleDash = !!yargs.getOptions().configuration['populate--'];
|
||||
yargs
|
||||
.getInternalMethods()
|
||||
.postProcess(innerArgv, populateDoubleDash, false, false);
|
||||
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false);
|
||||
innerArgv = maybeAsyncResult(innerArgv, result => {
|
||||
const handlerResult = commandHandler.handler(result);
|
||||
return isPromise(handlerResult)
|
||||
? handlerResult.then(() => result)
|
||||
: result;
|
||||
});
|
||||
if (!isDefaultCommand) {
|
||||
yargs.getInternalMethods().getUsageInstance().cacheHelpMessage();
|
||||
}
|
||||
if (isPromise(innerArgv) &&
|
||||
!yargs.getInternalMethods().hasParseCallback()) {
|
||||
innerArgv.catch(error => {
|
||||
try {
|
||||
yargs.getInternalMethods().getUsageInstance().fail(null, error);
|
||||
}
|
||||
catch (_err) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!isDefaultCommand) {
|
||||
currentContext.commands.pop();
|
||||
currentContext.fullCommands.pop();
|
||||
}
|
||||
return innerArgv;
|
||||
}
|
||||
applyMiddlewareAndGetResult(isDefaultCommand, commandHandler, innerArgv, currentContext, helpOnly, aliases, yargs) {
|
||||
let positionalMap = {};
|
||||
if (helpOnly)
|
||||
return innerArgv;
|
||||
if (!yargs.getInternalMethods().getHasOutput()) {
|
||||
positionalMap = this.populatePositionals(commandHandler, innerArgv, currentContext, yargs);
|
||||
}
|
||||
const middlewares = this.globalMiddleware
|
||||
.getMiddleware()
|
||||
.slice(0)
|
||||
.concat(commandHandler.middlewares);
|
||||
const maybePromiseArgv = applyMiddleware(innerArgv, yargs, middlewares, true);
|
||||
return isPromise(maybePromiseArgv)
|
||||
? maybePromiseArgv.then(resolvedInnerArgv => this.handleValidationAndGetResult(isDefaultCommand, commandHandler, resolvedInnerArgv, currentContext, aliases, yargs, middlewares, positionalMap))
|
||||
: this.handleValidationAndGetResult(isDefaultCommand, commandHandler, maybePromiseArgv, currentContext, aliases, yargs, middlewares, positionalMap);
|
||||
}
|
||||
populatePositionals(commandHandler, argv, context, yargs) {
|
||||
argv._ = argv._.slice(context.commands.length);
|
||||
const demanded = commandHandler.demanded.slice(0);
|
||||
const optional = commandHandler.optional.slice(0);
|
||||
const positionalMap = {};
|
||||
this.validation.positionalCount(demanded.length, argv._.length);
|
||||
while (demanded.length) {
|
||||
const demand = demanded.shift();
|
||||
this.populatePositional(demand, argv, positionalMap);
|
||||
}
|
||||
while (optional.length) {
|
||||
const maybe = optional.shift();
|
||||
this.populatePositional(maybe, argv, positionalMap);
|
||||
}
|
||||
argv._ = context.commands.concat(argv._.map(a => '' + a));
|
||||
this.postProcessPositionals(argv, positionalMap, this.cmdToParseOptions(commandHandler.original), yargs);
|
||||
return positionalMap;
|
||||
}
|
||||
populatePositional(positional, argv, positionalMap) {
|
||||
const cmd = positional.cmd[0];
|
||||
if (positional.variadic) {
|
||||
positionalMap[cmd] = argv._.splice(0).map(String);
|
||||
}
|
||||
else {
|
||||
if (argv._.length)
|
||||
positionalMap[cmd] = [String(argv._.shift())];
|
||||
}
|
||||
}
|
||||
cmdToParseOptions(cmdString) {
|
||||
const parseOptions = {
|
||||
array: [],
|
||||
default: {},
|
||||
alias: {},
|
||||
demand: {},
|
||||
};
|
||||
const parsed = parseCommand(cmdString);
|
||||
parsed.demanded.forEach(d => {
|
||||
const [cmd, ...aliases] = d.cmd;
|
||||
if (d.variadic) {
|
||||
parseOptions.array.push(cmd);
|
||||
parseOptions.default[cmd] = [];
|
||||
}
|
||||
parseOptions.alias[cmd] = aliases;
|
||||
parseOptions.demand[cmd] = true;
|
||||
});
|
||||
parsed.optional.forEach(o => {
|
||||
const [cmd, ...aliases] = o.cmd;
|
||||
if (o.variadic) {
|
||||
parseOptions.array.push(cmd);
|
||||
parseOptions.default[cmd] = [];
|
||||
}
|
||||
parseOptions.alias[cmd] = aliases;
|
||||
});
|
||||
return parseOptions;
|
||||
}
|
||||
postProcessPositionals(argv, positionalMap, parseOptions, yargs) {
|
||||
const options = Object.assign({}, yargs.getOptions());
|
||||
options.default = Object.assign(parseOptions.default, options.default);
|
||||
for (const key of Object.keys(parseOptions.alias)) {
|
||||
options.alias[key] = (options.alias[key] || []).concat(parseOptions.alias[key]);
|
||||
}
|
||||
options.array = options.array.concat(parseOptions.array);
|
||||
options.config = {};
|
||||
const unparsed = [];
|
||||
Object.keys(positionalMap).forEach(key => {
|
||||
positionalMap[key].map(value => {
|
||||
if (options.configuration['unknown-options-as-args'])
|
||||
options.key[key] = true;
|
||||
unparsed.push(`--${key}`);
|
||||
unparsed.push(value);
|
||||
});
|
||||
});
|
||||
if (!unparsed.length)
|
||||
return;
|
||||
const config = Object.assign({}, options.configuration, {
|
||||
'populate--': false,
|
||||
});
|
||||
const parsed = this.shim.Parser.detailed(unparsed, Object.assign({}, options, {
|
||||
configuration: config,
|
||||
}));
|
||||
if (parsed.error) {
|
||||
yargs
|
||||
.getInternalMethods()
|
||||
.getUsageInstance()
|
||||
.fail(parsed.error.message, parsed.error);
|
||||
}
|
||||
else {
|
||||
const positionalKeys = Object.keys(positionalMap);
|
||||
Object.keys(positionalMap).forEach(key => {
|
||||
positionalKeys.push(...parsed.aliases[key]);
|
||||
});
|
||||
Object.keys(parsed.argv).forEach(key => {
|
||||
if (positionalKeys.includes(key)) {
|
||||
if (!positionalMap[key])
|
||||
positionalMap[key] = parsed.argv[key];
|
||||
if (!this.isInConfigs(yargs, key) &&
|
||||
!this.isDefaulted(yargs, key) &&
|
||||
Object.prototype.hasOwnProperty.call(argv, key) &&
|
||||
Object.prototype.hasOwnProperty.call(parsed.argv, key) &&
|
||||
(Array.isArray(argv[key]) || Array.isArray(parsed.argv[key]))) {
|
||||
argv[key] = [].concat(argv[key], parsed.argv[key]);
|
||||
}
|
||||
else {
|
||||
argv[key] = parsed.argv[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
isDefaulted(yargs, key) {
|
||||
const { default: defaults } = yargs.getOptions();
|
||||
return (Object.prototype.hasOwnProperty.call(defaults, key) ||
|
||||
Object.prototype.hasOwnProperty.call(defaults, this.shim.Parser.camelCase(key)));
|
||||
}
|
||||
isInConfigs(yargs, key) {
|
||||
const { configObjects } = yargs.getOptions();
|
||||
return (configObjects.some(c => Object.prototype.hasOwnProperty.call(c, key)) ||
|
||||
configObjects.some(c => Object.prototype.hasOwnProperty.call(c, this.shim.Parser.camelCase(key))));
|
||||
}
|
||||
runDefaultBuilderOn(yargs) {
|
||||
if (!this.defaultCommand)
|
||||
return;
|
||||
if (this.shouldUpdateUsage(yargs)) {
|
||||
const commandString = DEFAULT_MARKER.test(this.defaultCommand.original)
|
||||
? this.defaultCommand.original
|
||||
: this.defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ');
|
||||
yargs
|
||||
.getInternalMethods()
|
||||
.getUsageInstance()
|
||||
.usage(commandString, this.defaultCommand.description);
|
||||
}
|
||||
const builder = this.defaultCommand.builder;
|
||||
if (isCommandBuilderCallback(builder)) {
|
||||
return builder(yargs, true);
|
||||
}
|
||||
else if (!isCommandBuilderDefinition(builder)) {
|
||||
Object.keys(builder).forEach(key => {
|
||||
yargs.option(key, builder[key]);
|
||||
});
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
moduleName(obj) {
|
||||
const mod = whichModule(obj);
|
||||
if (!mod)
|
||||
throw new Error(`No command name given for module: ${this.shim.inspect(obj)}`);
|
||||
return this.commandFromFilename(mod.filename);
|
||||
}
|
||||
commandFromFilename(filename) {
|
||||
return this.shim.path.basename(filename, this.shim.path.extname(filename));
|
||||
}
|
||||
extractDesc({ describe, description, desc }) {
|
||||
for (const test of [describe, description, desc]) {
|
||||
if (typeof test === 'string' || test === false)
|
||||
return test;
|
||||
assertNotStrictEqual(test, true, this.shim);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
freeze() {
|
||||
this.frozens.push({
|
||||
handlers: this.handlers,
|
||||
aliasMap: this.aliasMap,
|
||||
defaultCommand: this.defaultCommand,
|
||||
});
|
||||
}
|
||||
unfreeze() {
|
||||
const frozen = this.frozens.pop();
|
||||
assertNotStrictEqual(frozen, undefined, this.shim);
|
||||
({
|
||||
handlers: this.handlers,
|
||||
aliasMap: this.aliasMap,
|
||||
defaultCommand: this.defaultCommand,
|
||||
} = frozen);
|
||||
}
|
||||
reset() {
|
||||
this.handlers = {};
|
||||
this.aliasMap = {};
|
||||
this.defaultCommand = undefined;
|
||||
this.requireCache = new Set();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
export function command(usage, validation, globalMiddleware, shim) {
|
||||
return new CommandInstance(usage, validation, globalMiddleware, shim);
|
||||
}
|
||||
export function isCommandBuilderDefinition(builder) {
|
||||
return (typeof builder === 'object' &&
|
||||
!!builder.builder &&
|
||||
typeof builder.handler === 'function');
|
||||
}
|
||||
function isCommandAndAliases(cmd) {
|
||||
return cmd.every(c => typeof c === 'string');
|
||||
}
|
||||
export function isCommandBuilderCallback(builder) {
|
||||
return typeof builder === 'function';
|
||||
}
|
||||
function isCommandBuilderOptionDefinitions(builder) {
|
||||
return typeof builder === 'object';
|
||||
}
|
||||
export function isCommandHandlerDefinition(cmd) {
|
||||
return typeof cmd === 'object' && !Array.isArray(cmd);
|
||||
}
|
48
node_modules/yargs/build/lib/completion-templates.js
generated
vendored
48
node_modules/yargs/build/lib/completion-templates.js
generated
vendored
@ -1,48 +0,0 @@
|
||||
export const completionShTemplate = `###-begin-{{app_name}}-completions-###
|
||||
#
|
||||
# yargs command completion script
|
||||
#
|
||||
# Installation: {{app_path}} {{completion_command}} >> ~/.bashrc
|
||||
# or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.
|
||||
#
|
||||
_{{app_name}}_yargs_completions()
|
||||
{
|
||||
local cur_word args type_list
|
||||
|
||||
cur_word="\${COMP_WORDS[COMP_CWORD]}"
|
||||
args=("\${COMP_WORDS[@]}")
|
||||
|
||||
# ask yargs to generate completions.
|
||||
type_list=$({{app_path}} --get-yargs-completions "\${args[@]}")
|
||||
|
||||
COMPREPLY=( $(compgen -W "\${type_list}" -- \${cur_word}) )
|
||||
|
||||
# if no match was found, fall back to filename completion
|
||||
if [ \${#COMPREPLY[@]} -eq 0 ]; then
|
||||
COMPREPLY=()
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
complete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name}}
|
||||
###-end-{{app_name}}-completions-###
|
||||
`;
|
||||
export const completionZshTemplate = `#compdef {{app_name}}
|
||||
###-begin-{{app_name}}-completions-###
|
||||
#
|
||||
# yargs command completion script
|
||||
#
|
||||
# Installation: {{app_path}} {{completion_command}} >> ~/.zshrc
|
||||
# or {{app_path}} {{completion_command}} >> ~/.zprofile on OSX.
|
||||
#
|
||||
_{{app_name}}_yargs_completions()
|
||||
{
|
||||
local reply
|
||||
local si=$IFS
|
||||
IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {{app_path}} --get-yargs-completions "\${words[@]}"))
|
||||
IFS=$si
|
||||
_describe 'values' reply
|
||||
}
|
||||
compdef _{{app_name}}_yargs_completions {{app_name}}
|
||||
###-end-{{app_name}}-completions-###
|
||||
`;
|
243
node_modules/yargs/build/lib/completion.js
generated
vendored
243
node_modules/yargs/build/lib/completion.js
generated
vendored
@ -1,243 +0,0 @@
|
||||
import { isCommandBuilderCallback } from './command.js';
|
||||
import { assertNotStrictEqual } from './typings/common-types.js';
|
||||
import * as templates from './completion-templates.js';
|
||||
import { isPromise } from './utils/is-promise.js';
|
||||
import { parseCommand } from './parse-command.js';
|
||||
export class Completion {
|
||||
constructor(yargs, usage, command, shim) {
|
||||
var _a, _b, _c;
|
||||
this.yargs = yargs;
|
||||
this.usage = usage;
|
||||
this.command = command;
|
||||
this.shim = shim;
|
||||
this.completionKey = 'get-yargs-completions';
|
||||
this.aliases = null;
|
||||
this.customCompletionFunction = null;
|
||||
this.indexAfterLastReset = 0;
|
||||
this.zshShell =
|
||||
(_c = (((_a = this.shim.getEnv('SHELL')) === null || _a === void 0 ? void 0 : _a.includes('zsh')) ||
|
||||
((_b = this.shim.getEnv('ZSH_NAME')) === null || _b === void 0 ? void 0 : _b.includes('zsh')))) !== null && _c !== void 0 ? _c : false;
|
||||
}
|
||||
defaultCompletion(args, argv, current, done) {
|
||||
const handlers = this.command.getCommandHandlers();
|
||||
for (let i = 0, ii = args.length; i < ii; ++i) {
|
||||
if (handlers[args[i]] && handlers[args[i]].builder) {
|
||||
const builder = handlers[args[i]].builder;
|
||||
if (isCommandBuilderCallback(builder)) {
|
||||
this.indexAfterLastReset = i + 1;
|
||||
const y = this.yargs.getInternalMethods().reset();
|
||||
builder(y, true);
|
||||
return y.argv;
|
||||
}
|
||||
}
|
||||
}
|
||||
const completions = [];
|
||||
this.commandCompletions(completions, args, current);
|
||||
this.optionCompletions(completions, args, argv, current);
|
||||
this.choicesFromOptionsCompletions(completions, args, argv, current);
|
||||
this.choicesFromPositionalsCompletions(completions, args, argv, current);
|
||||
done(null, completions);
|
||||
}
|
||||
commandCompletions(completions, args, current) {
|
||||
const parentCommands = this.yargs
|
||||
.getInternalMethods()
|
||||
.getContext().commands;
|
||||
if (!current.match(/^-/) &&
|
||||
parentCommands[parentCommands.length - 1] !== current &&
|
||||
!this.previousArgHasChoices(args)) {
|
||||
this.usage.getCommands().forEach(usageCommand => {
|
||||
const commandName = parseCommand(usageCommand[0]).cmd;
|
||||
if (args.indexOf(commandName) === -1) {
|
||||
if (!this.zshShell) {
|
||||
completions.push(commandName);
|
||||
}
|
||||
else {
|
||||
const desc = usageCommand[1] || '';
|
||||
completions.push(commandName.replace(/:/g, '\\:') + ':' + desc);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
optionCompletions(completions, args, argv, current) {
|
||||
if ((current.match(/^-/) || (current === '' && completions.length === 0)) &&
|
||||
!this.previousArgHasChoices(args)) {
|
||||
const options = this.yargs.getOptions();
|
||||
const positionalKeys = this.yargs.getGroups()[this.usage.getPositionalGroupName()] || [];
|
||||
Object.keys(options.key).forEach(key => {
|
||||
const negable = !!options.configuration['boolean-negation'] &&
|
||||
options.boolean.includes(key);
|
||||
const isPositionalKey = positionalKeys.includes(key);
|
||||
if (!isPositionalKey &&
|
||||
!options.hiddenOptions.includes(key) &&
|
||||
!this.argsContainKey(args, key, negable)) {
|
||||
this.completeOptionKey(key, completions, current, negable && !!options.default[key]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
choicesFromOptionsCompletions(completions, args, argv, current) {
|
||||
if (this.previousArgHasChoices(args)) {
|
||||
const choices = this.getPreviousArgChoices(args);
|
||||
if (choices && choices.length > 0) {
|
||||
completions.push(...choices.map(c => c.replace(/:/g, '\\:')));
|
||||
}
|
||||
}
|
||||
}
|
||||
choicesFromPositionalsCompletions(completions, args, argv, current) {
|
||||
if (current === '' &&
|
||||
completions.length > 0 &&
|
||||
this.previousArgHasChoices(args)) {
|
||||
return;
|
||||
}
|
||||
const positionalKeys = this.yargs.getGroups()[this.usage.getPositionalGroupName()] || [];
|
||||
const offset = Math.max(this.indexAfterLastReset, this.yargs.getInternalMethods().getContext().commands.length +
|
||||
1);
|
||||
const positionalKey = positionalKeys[argv._.length - offset - 1];
|
||||
if (!positionalKey) {
|
||||
return;
|
||||
}
|
||||
const choices = this.yargs.getOptions().choices[positionalKey] || [];
|
||||
for (const choice of choices) {
|
||||
if (choice.startsWith(current)) {
|
||||
completions.push(choice.replace(/:/g, '\\:'));
|
||||
}
|
||||
}
|
||||
}
|
||||
getPreviousArgChoices(args) {
|
||||
if (args.length < 1)
|
||||
return;
|
||||
let previousArg = args[args.length - 1];
|
||||
let filter = '';
|
||||
if (!previousArg.startsWith('-') && args.length > 1) {
|
||||
filter = previousArg;
|
||||
previousArg = args[args.length - 2];
|
||||
}
|
||||
if (!previousArg.startsWith('-'))
|
||||
return;
|
||||
const previousArgKey = previousArg.replace(/^-+/, '');
|
||||
const options = this.yargs.getOptions();
|
||||
const possibleAliases = [
|
||||
previousArgKey,
|
||||
...(this.yargs.getAliases()[previousArgKey] || []),
|
||||
];
|
||||
let choices;
|
||||
for (const possibleAlias of possibleAliases) {
|
||||
if (Object.prototype.hasOwnProperty.call(options.key, possibleAlias) &&
|
||||
Array.isArray(options.choices[possibleAlias])) {
|
||||
choices = options.choices[possibleAlias];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (choices) {
|
||||
return choices.filter(choice => !filter || choice.startsWith(filter));
|
||||
}
|
||||
}
|
||||
previousArgHasChoices(args) {
|
||||
const choices = this.getPreviousArgChoices(args);
|
||||
return choices !== undefined && choices.length > 0;
|
||||
}
|
||||
argsContainKey(args, key, negable) {
|
||||
const argsContains = (s) => args.indexOf((/^[^0-9]$/.test(s) ? '-' : '--') + s) !== -1;
|
||||
if (argsContains(key))
|
||||
return true;
|
||||
if (negable && argsContains(`no-${key}`))
|
||||
return true;
|
||||
if (this.aliases) {
|
||||
for (const alias of this.aliases[key]) {
|
||||
if (argsContains(alias))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
completeOptionKey(key, completions, current, negable) {
|
||||
var _a, _b, _c, _d;
|
||||
let keyWithDesc = key;
|
||||
if (this.zshShell) {
|
||||
const descs = this.usage.getDescriptions();
|
||||
const aliasKey = (_b = (_a = this === null || this === void 0 ? void 0 : this.aliases) === null || _a === void 0 ? void 0 : _a[key]) === null || _b === void 0 ? void 0 : _b.find(alias => {
|
||||
const desc = descs[alias];
|
||||
return typeof desc === 'string' && desc.length > 0;
|
||||
});
|
||||
const descFromAlias = aliasKey ? descs[aliasKey] : undefined;
|
||||
const desc = (_d = (_c = descs[key]) !== null && _c !== void 0 ? _c : descFromAlias) !== null && _d !== void 0 ? _d : '';
|
||||
keyWithDesc = `${key.replace(/:/g, '\\:')}:${desc
|
||||
.replace('__yargsString__:', '')
|
||||
.replace(/(\r\n|\n|\r)/gm, ' ')}`;
|
||||
}
|
||||
const startsByTwoDashes = (s) => /^--/.test(s);
|
||||
const isShortOption = (s) => /^[^0-9]$/.test(s);
|
||||
const dashes = !startsByTwoDashes(current) && isShortOption(key) ? '-' : '--';
|
||||
completions.push(dashes + keyWithDesc);
|
||||
if (negable) {
|
||||
completions.push(dashes + 'no-' + keyWithDesc);
|
||||
}
|
||||
}
|
||||
customCompletion(args, argv, current, done) {
|
||||
assertNotStrictEqual(this.customCompletionFunction, null, this.shim);
|
||||
if (isSyncCompletionFunction(this.customCompletionFunction)) {
|
||||
const result = this.customCompletionFunction(current, argv);
|
||||
if (isPromise(result)) {
|
||||
return result
|
||||
.then(list => {
|
||||
this.shim.process.nextTick(() => {
|
||||
done(null, list);
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
this.shim.process.nextTick(() => {
|
||||
done(err, undefined);
|
||||
});
|
||||
});
|
||||
}
|
||||
return done(null, result);
|
||||
}
|
||||
else if (isFallbackCompletionFunction(this.customCompletionFunction)) {
|
||||
return this.customCompletionFunction(current, argv, (onCompleted = done) => this.defaultCompletion(args, argv, current, onCompleted), completions => {
|
||||
done(null, completions);
|
||||
});
|
||||
}
|
||||
else {
|
||||
return this.customCompletionFunction(current, argv, completions => {
|
||||
done(null, completions);
|
||||
});
|
||||
}
|
||||
}
|
||||
getCompletion(args, done) {
|
||||
const current = args.length ? args[args.length - 1] : '';
|
||||
const argv = this.yargs.parse(args, true);
|
||||
const completionFunction = this.customCompletionFunction
|
||||
? (argv) => this.customCompletion(args, argv, current, done)
|
||||
: (argv) => this.defaultCompletion(args, argv, current, done);
|
||||
return isPromise(argv)
|
||||
? argv.then(completionFunction)
|
||||
: completionFunction(argv);
|
||||
}
|
||||
generateCompletionScript($0, cmd) {
|
||||
let script = this.zshShell
|
||||
? templates.completionZshTemplate
|
||||
: templates.completionShTemplate;
|
||||
const name = this.shim.path.basename($0);
|
||||
if ($0.match(/\.js$/))
|
||||
$0 = `./${$0}`;
|
||||
script = script.replace(/{{app_name}}/g, name);
|
||||
script = script.replace(/{{completion_command}}/g, cmd);
|
||||
return script.replace(/{{app_path}}/g, $0);
|
||||
}
|
||||
registerFunction(fn) {
|
||||
this.customCompletionFunction = fn;
|
||||
}
|
||||
setParsed(parsed) {
|
||||
this.aliases = parsed.aliases;
|
||||
}
|
||||
}
|
||||
export function completion(yargs, usage, command, shim) {
|
||||
return new Completion(yargs, usage, command, shim);
|
||||
}
|
||||
function isSyncCompletionFunction(completionFunction) {
|
||||
return completionFunction.length < 3;
|
||||
}
|
||||
function isFallbackCompletionFunction(completionFunction) {
|
||||
return completionFunction.length > 3;
|
||||
}
|
88
node_modules/yargs/build/lib/middleware.js
generated
vendored
88
node_modules/yargs/build/lib/middleware.js
generated
vendored
@ -1,88 +0,0 @@
|
||||
import { argsert } from './argsert.js';
|
||||
import { isPromise } from './utils/is-promise.js';
|
||||
export class GlobalMiddleware {
|
||||
constructor(yargs) {
|
||||
this.globalMiddleware = [];
|
||||
this.frozens = [];
|
||||
this.yargs = yargs;
|
||||
}
|
||||
addMiddleware(callback, applyBeforeValidation, global = true, mutates = false) {
|
||||
argsert('<array|function> [boolean] [boolean] [boolean]', [callback, applyBeforeValidation, global], arguments.length);
|
||||
if (Array.isArray(callback)) {
|
||||
for (let i = 0; i < callback.length; i++) {
|
||||
if (typeof callback[i] !== 'function') {
|
||||
throw Error('middleware must be a function');
|
||||
}
|
||||
const m = callback[i];
|
||||
m.applyBeforeValidation = applyBeforeValidation;
|
||||
m.global = global;
|
||||
}
|
||||
Array.prototype.push.apply(this.globalMiddleware, callback);
|
||||
}
|
||||
else if (typeof callback === 'function') {
|
||||
const m = callback;
|
||||
m.applyBeforeValidation = applyBeforeValidation;
|
||||
m.global = global;
|
||||
m.mutates = mutates;
|
||||
this.globalMiddleware.push(callback);
|
||||
}
|
||||
return this.yargs;
|
||||
}
|
||||
addCoerceMiddleware(callback, option) {
|
||||
const aliases = this.yargs.getAliases();
|
||||
this.globalMiddleware = this.globalMiddleware.filter(m => {
|
||||
const toCheck = [...(aliases[option] || []), option];
|
||||
if (!m.option)
|
||||
return true;
|
||||
else
|
||||
return !toCheck.includes(m.option);
|
||||
});
|
||||
callback.option = option;
|
||||
return this.addMiddleware(callback, true, true, true);
|
||||
}
|
||||
getMiddleware() {
|
||||
return this.globalMiddleware;
|
||||
}
|
||||
freeze() {
|
||||
this.frozens.push([...this.globalMiddleware]);
|
||||
}
|
||||
unfreeze() {
|
||||
const frozen = this.frozens.pop();
|
||||
if (frozen !== undefined)
|
||||
this.globalMiddleware = frozen;
|
||||
}
|
||||
reset() {
|
||||
this.globalMiddleware = this.globalMiddleware.filter(m => m.global);
|
||||
}
|
||||
}
|
||||
export function commandMiddlewareFactory(commandMiddleware) {
|
||||
if (!commandMiddleware)
|
||||
return [];
|
||||
return commandMiddleware.map(middleware => {
|
||||
middleware.applyBeforeValidation = false;
|
||||
return middleware;
|
||||
});
|
||||
}
|
||||
export function applyMiddleware(argv, yargs, middlewares, beforeValidation) {
|
||||
return middlewares.reduce((acc, middleware) => {
|
||||
if (middleware.applyBeforeValidation !== beforeValidation) {
|
||||
return acc;
|
||||
}
|
||||
if (middleware.mutates) {
|
||||
if (middleware.applied)
|
||||
return acc;
|
||||
middleware.applied = true;
|
||||
}
|
||||
if (isPromise(acc)) {
|
||||
return acc
|
||||
.then(initialObj => Promise.all([initialObj, middleware(initialObj, yargs)]))
|
||||
.then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj));
|
||||
}
|
||||
else {
|
||||
const result = middleware(acc, yargs);
|
||||
return isPromise(result)
|
||||
? result.then(middlewareObj => Object.assign(acc, middlewareObj))
|
||||
: Object.assign(acc, result);
|
||||
}
|
||||
}, argv);
|
||||
}
|
32
node_modules/yargs/build/lib/parse-command.js
generated
vendored
32
node_modules/yargs/build/lib/parse-command.js
generated
vendored
@ -1,32 +0,0 @@
|
||||
export function parseCommand(cmd) {
|
||||
const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ');
|
||||
const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/);
|
||||
const bregex = /\.*[\][<>]/g;
|
||||
const firstCommand = splitCommand.shift();
|
||||
if (!firstCommand)
|
||||
throw new Error(`No command found in: ${cmd}`);
|
||||
const parsedCommand = {
|
||||
cmd: firstCommand.replace(bregex, ''),
|
||||
demanded: [],
|
||||
optional: [],
|
||||
};
|
||||
splitCommand.forEach((cmd, i) => {
|
||||
let variadic = false;
|
||||
cmd = cmd.replace(/\s/g, '');
|
||||
if (/\.+[\]>]/.test(cmd) && i === splitCommand.length - 1)
|
||||
variadic = true;
|
||||
if (/^\[/.test(cmd)) {
|
||||
parsedCommand.optional.push({
|
||||
cmd: cmd.replace(bregex, '').split('|'),
|
||||
variadic,
|
||||
});
|
||||
}
|
||||
else {
|
||||
parsedCommand.demanded.push({
|
||||
cmd: cmd.replace(bregex, '').split('|'),
|
||||
variadic,
|
||||
});
|
||||
}
|
||||
});
|
||||
return parsedCommand;
|
||||
}
|
9
node_modules/yargs/build/lib/typings/common-types.js
generated
vendored
9
node_modules/yargs/build/lib/typings/common-types.js
generated
vendored
@ -1,9 +0,0 @@
|
||||
export function assertNotStrictEqual(actual, expected, shim, message) {
|
||||
shim.assert.notStrictEqual(actual, expected, message);
|
||||
}
|
||||
export function assertSingleKey(actual, shim) {
|
||||
shim.assert.strictEqual(typeof actual, 'string');
|
||||
}
|
||||
export function objectKeys(object) {
|
||||
return Object.keys(object);
|
||||
}
|
1
node_modules/yargs/build/lib/typings/yargs-parser-types.js
generated
vendored
1
node_modules/yargs/build/lib/typings/yargs-parser-types.js
generated
vendored
@ -1 +0,0 @@
|
||||
export {};
|
584
node_modules/yargs/build/lib/usage.js
generated
vendored
584
node_modules/yargs/build/lib/usage.js
generated
vendored
@ -1,584 +0,0 @@
|
||||
import { objFilter } from './utils/obj-filter.js';
|
||||
import { YError } from './yerror.js';
|
||||
import setBlocking from './utils/set-blocking.js';
|
||||
function isBoolean(fail) {
|
||||
return typeof fail === 'boolean';
|
||||
}
|
||||
export function usage(yargs, shim) {
|
||||
const __ = shim.y18n.__;
|
||||
const self = {};
|
||||
const fails = [];
|
||||
self.failFn = function failFn(f) {
|
||||
fails.push(f);
|
||||
};
|
||||
let failMessage = null;
|
||||
let globalFailMessage = null;
|
||||
let showHelpOnFail = true;
|
||||
self.showHelpOnFail = function showHelpOnFailFn(arg1 = true, arg2) {
|
||||
const [enabled, message] = typeof arg1 === 'string' ? [true, arg1] : [arg1, arg2];
|
||||
if (yargs.getInternalMethods().isGlobalContext()) {
|
||||
globalFailMessage = message;
|
||||
}
|
||||
failMessage = message;
|
||||
showHelpOnFail = enabled;
|
||||
return self;
|
||||
};
|
||||
let failureOutput = false;
|
||||
self.fail = function fail(msg, err) {
|
||||
const logger = yargs.getInternalMethods().getLoggerInstance();
|
||||
if (fails.length) {
|
||||
for (let i = fails.length - 1; i >= 0; --i) {
|
||||
const fail = fails[i];
|
||||
if (isBoolean(fail)) {
|
||||
if (err)
|
||||
throw err;
|
||||
else if (msg)
|
||||
throw Error(msg);
|
||||
}
|
||||
else {
|
||||
fail(msg, err, self);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (yargs.getExitProcess())
|
||||
setBlocking(true);
|
||||
if (!failureOutput) {
|
||||
failureOutput = true;
|
||||
if (showHelpOnFail) {
|
||||
yargs.showHelp('error');
|
||||
logger.error();
|
||||
}
|
||||
if (msg || err)
|
||||
logger.error(msg || err);
|
||||
const globalOrCommandFailMessage = failMessage || globalFailMessage;
|
||||
if (globalOrCommandFailMessage) {
|
||||
if (msg || err)
|
||||
logger.error('');
|
||||
logger.error(globalOrCommandFailMessage);
|
||||
}
|
||||
}
|
||||
err = err || new YError(msg);
|
||||
if (yargs.getExitProcess()) {
|
||||
return yargs.exit(1);
|
||||
}
|
||||
else if (yargs.getInternalMethods().hasParseCallback()) {
|
||||
return yargs.exit(1, err);
|
||||
}
|
||||
else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
let usages = [];
|
||||
let usageDisabled = false;
|
||||
self.usage = (msg, description) => {
|
||||
if (msg === null) {
|
||||
usageDisabled = true;
|
||||
usages = [];
|
||||
return self;
|
||||
}
|
||||
usageDisabled = false;
|
||||
usages.push([msg, description || '']);
|
||||
return self;
|
||||
};
|
||||
self.getUsage = () => {
|
||||
return usages;
|
||||
};
|
||||
self.getUsageDisabled = () => {
|
||||
return usageDisabled;
|
||||
};
|
||||
self.getPositionalGroupName = () => {
|
||||
return __('Positionals:');
|
||||
};
|
||||
let examples = [];
|
||||
self.example = (cmd, description) => {
|
||||
examples.push([cmd, description || '']);
|
||||
};
|
||||
let commands = [];
|
||||
self.command = function command(cmd, description, isDefault, aliases, deprecated = false) {
|
||||
if (isDefault) {
|
||||
commands = commands.map(cmdArray => {
|
||||
cmdArray[2] = false;
|
||||
return cmdArray;
|
||||
});
|
||||
}
|
||||
commands.push([cmd, description || '', isDefault, aliases, deprecated]);
|
||||
};
|
||||
self.getCommands = () => commands;
|
||||
let descriptions = {};
|
||||
self.describe = function describe(keyOrKeys, desc) {
|
||||
if (Array.isArray(keyOrKeys)) {
|
||||
keyOrKeys.forEach(k => {
|
||||
self.describe(k, desc);
|
||||
});
|
||||
}
|
||||
else if (typeof keyOrKeys === 'object') {
|
||||
Object.keys(keyOrKeys).forEach(k => {
|
||||
self.describe(k, keyOrKeys[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
descriptions[keyOrKeys] = desc;
|
||||
}
|
||||
};
|
||||
self.getDescriptions = () => descriptions;
|
||||
let epilogs = [];
|
||||
self.epilog = msg => {
|
||||
epilogs.push(msg);
|
||||
};
|
||||
let wrapSet = false;
|
||||
let wrap;
|
||||
self.wrap = cols => {
|
||||
wrapSet = true;
|
||||
wrap = cols;
|
||||
};
|
||||
self.getWrap = () => {
|
||||
if (shim.getEnv('YARGS_DISABLE_WRAP')) {
|
||||
return null;
|
||||
}
|
||||
if (!wrapSet) {
|
||||
wrap = windowWidth();
|
||||
wrapSet = true;
|
||||
}
|
||||
return wrap;
|
||||
};
|
||||
const deferY18nLookupPrefix = '__yargsString__:';
|
||||
self.deferY18nLookup = str => deferY18nLookupPrefix + str;
|
||||
self.help = function help() {
|
||||
if (cachedHelpMessage)
|
||||
return cachedHelpMessage;
|
||||
normalizeAliases();
|
||||
const base$0 = yargs.customScriptName
|
||||
? yargs.$0
|
||||
: shim.path.basename(yargs.$0);
|
||||
const demandedOptions = yargs.getDemandedOptions();
|
||||
const demandedCommands = yargs.getDemandedCommands();
|
||||
const deprecatedOptions = yargs.getDeprecatedOptions();
|
||||
const groups = yargs.getGroups();
|
||||
const options = yargs.getOptions();
|
||||
let keys = [];
|
||||
keys = keys.concat(Object.keys(descriptions));
|
||||
keys = keys.concat(Object.keys(demandedOptions));
|
||||
keys = keys.concat(Object.keys(demandedCommands));
|
||||
keys = keys.concat(Object.keys(options.default));
|
||||
keys = keys.filter(filterHiddenOptions);
|
||||
keys = Object.keys(keys.reduce((acc, key) => {
|
||||
if (key !== '_')
|
||||
acc[key] = true;
|
||||
return acc;
|
||||
}, {}));
|
||||
const theWrap = self.getWrap();
|
||||
const ui = shim.cliui({
|
||||
width: theWrap,
|
||||
wrap: !!theWrap,
|
||||
});
|
||||
if (!usageDisabled) {
|
||||
if (usages.length) {
|
||||
usages.forEach(usage => {
|
||||
ui.div({ text: `${usage[0].replace(/\$0/g, base$0)}` });
|
||||
if (usage[1]) {
|
||||
ui.div({ text: `${usage[1]}`, padding: [1, 0, 0, 0] });
|
||||
}
|
||||
});
|
||||
ui.div();
|
||||
}
|
||||
else if (commands.length) {
|
||||
let u = null;
|
||||
if (demandedCommands._) {
|
||||
u = `${base$0} <${__('command')}>\n`;
|
||||
}
|
||||
else {
|
||||
u = `${base$0} [${__('command')}]\n`;
|
||||
}
|
||||
ui.div(`${u}`);
|
||||
}
|
||||
}
|
||||
if (commands.length > 1 || (commands.length === 1 && !commands[0][2])) {
|
||||
ui.div(__('Commands:'));
|
||||
const context = yargs.getInternalMethods().getContext();
|
||||
const parentCommands = context.commands.length
|
||||
? `${context.commands.join(' ')} `
|
||||
: '';
|
||||
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 = `${prefix}${parentCommands}${command[0].replace(/^\$0 ?/, '')}`;
|
||||
ui.span({
|
||||
text: commandString,
|
||||
padding: [0, 2, 0, 2],
|
||||
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4,
|
||||
}, { text: command[1] });
|
||||
const hints = [];
|
||||
if (command[2])
|
||||
hints.push(`[${__('default')}]`);
|
||||
if (command[3] && command[3].length) {
|
||||
hints.push(`[${__('aliases:')} ${command[3].join(', ')}]`);
|
||||
}
|
||||
if (command[4]) {
|
||||
if (typeof command[4] === 'string') {
|
||||
hints.push(`[${__('deprecated: %s', command[4])}]`);
|
||||
}
|
||||
else {
|
||||
hints.push(`[${__('deprecated')}]`);
|
||||
}
|
||||
}
|
||||
if (hints.length) {
|
||||
ui.div({
|
||||
text: hints.join(' '),
|
||||
padding: [0, 0, 0, 2],
|
||||
align: 'right',
|
||||
});
|
||||
}
|
||||
else {
|
||||
ui.div();
|
||||
}
|
||||
});
|
||||
ui.div();
|
||||
}
|
||||
const aliasKeys = (Object.keys(options.alias) || []).concat(Object.keys(yargs.parsed.newAliases) || []);
|
||||
keys = keys.filter(key => !yargs.parsed.newAliases[key] &&
|
||||
aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1));
|
||||
const defaultGroup = __('Options:');
|
||||
if (!groups[defaultGroup])
|
||||
groups[defaultGroup] = [];
|
||||
addUngroupedKeys(keys, options.alias, groups, defaultGroup);
|
||||
const isLongSwitch = (sw) => /^--/.test(getText(sw));
|
||||
const displayedGroups = Object.keys(groups)
|
||||
.filter(groupName => groups[groupName].length > 0)
|
||||
.map(groupName => {
|
||||
const normalizedKeys = groups[groupName]
|
||||
.filter(filterHiddenOptions)
|
||||
.map(key => {
|
||||
if (aliasKeys.includes(key))
|
||||
return key;
|
||||
for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
|
||||
if ((options.alias[aliasKey] || []).includes(key))
|
||||
return aliasKey;
|
||||
}
|
||||
return key;
|
||||
});
|
||||
return { groupName, normalizedKeys };
|
||||
})
|
||||
.filter(({ normalizedKeys }) => normalizedKeys.length > 0)
|
||||
.map(({ groupName, normalizedKeys }) => {
|
||||
const switches = normalizedKeys.reduce((acc, key) => {
|
||||
acc[key] = [key]
|
||||
.concat(options.alias[key] || [])
|
||||
.map(sw => {
|
||||
if (groupName === self.getPositionalGroupName())
|
||||
return sw;
|
||||
else {
|
||||
return ((/^[0-9]$/.test(sw)
|
||||
? options.boolean.includes(key)
|
||||
? '-'
|
||||
: '--'
|
||||
: sw.length > 1
|
||||
? '--'
|
||||
: '-') + sw);
|
||||
}
|
||||
})
|
||||
.sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2)
|
||||
? 0
|
||||
: isLongSwitch(sw1)
|
||||
? 1
|
||||
: -1)
|
||||
.join(', ');
|
||||
return acc;
|
||||
}, {});
|
||||
return { groupName, normalizedKeys, switches };
|
||||
});
|
||||
const shortSwitchesUsed = displayedGroups
|
||||
.filter(({ groupName }) => groupName !== self.getPositionalGroupName())
|
||||
.some(({ normalizedKeys, switches }) => !normalizedKeys.every(key => isLongSwitch(switches[key])));
|
||||
if (shortSwitchesUsed) {
|
||||
displayedGroups
|
||||
.filter(({ groupName }) => groupName !== self.getPositionalGroupName())
|
||||
.forEach(({ normalizedKeys, switches }) => {
|
||||
normalizedKeys.forEach(key => {
|
||||
if (isLongSwitch(switches[key])) {
|
||||
switches[key] = addIndentation(switches[key], '-x, '.length);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => {
|
||||
ui.div(groupName);
|
||||
normalizedKeys.forEach(key => {
|
||||
const kswitch = switches[key];
|
||||
let desc = descriptions[key] || '';
|
||||
let type = null;
|
||||
if (desc.includes(deferY18nLookupPrefix))
|
||||
desc = __(desc.substring(deferY18nLookupPrefix.length));
|
||||
if (options.boolean.includes(key))
|
||||
type = `[${__('boolean')}]`;
|
||||
if (options.count.includes(key))
|
||||
type = `[${__('count')}]`;
|
||||
if (options.string.includes(key))
|
||||
type = `[${__('string')}]`;
|
||||
if (options.normalize.includes(key))
|
||||
type = `[${__('string')}]`;
|
||||
if (options.array.includes(key))
|
||||
type = `[${__('array')}]`;
|
||||
if (options.number.includes(key))
|
||||
type = `[${__('number')}]`;
|
||||
const deprecatedExtra = (deprecated) => typeof deprecated === 'string'
|
||||
? `[${__('deprecated: %s', deprecated)}]`
|
||||
: `[${__('deprecated')}]`;
|
||||
const extra = [
|
||||
key in deprecatedOptions
|
||||
? deprecatedExtra(deprecatedOptions[key])
|
||||
: null,
|
||||
type,
|
||||
key in demandedOptions ? `[${__('required')}]` : null,
|
||||
options.choices && options.choices[key]
|
||||
? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]`
|
||||
: null,
|
||||
defaultString(options.default[key], options.defaultDescription[key]),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
ui.span({
|
||||
text: getText(kswitch),
|
||||
padding: [0, 2, 0, 2 + getIndentation(kswitch)],
|
||||
width: maxWidth(switches, theWrap) + 4,
|
||||
}, desc);
|
||||
const shouldHideOptionExtras = yargs.getInternalMethods().getUsageConfiguration()['hide-types'] ===
|
||||
true;
|
||||
if (extra && !shouldHideOptionExtras)
|
||||
ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' });
|
||||
else
|
||||
ui.div();
|
||||
});
|
||||
ui.div();
|
||||
});
|
||||
if (examples.length) {
|
||||
ui.div(__('Examples:'));
|
||||
examples.forEach(example => {
|
||||
example[0] = example[0].replace(/\$0/g, base$0);
|
||||
});
|
||||
examples.forEach(example => {
|
||||
if (example[1] === '') {
|
||||
ui.div({
|
||||
text: example[0],
|
||||
padding: [0, 2, 0, 2],
|
||||
});
|
||||
}
|
||||
else {
|
||||
ui.div({
|
||||
text: example[0],
|
||||
padding: [0, 2, 0, 2],
|
||||
width: maxWidth(examples, theWrap) + 4,
|
||||
}, {
|
||||
text: example[1],
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.div();
|
||||
}
|
||||
if (epilogs.length > 0) {
|
||||
const e = epilogs
|
||||
.map(epilog => epilog.replace(/\$0/g, base$0))
|
||||
.join('\n');
|
||||
ui.div(`${e}\n`);
|
||||
}
|
||||
return ui.toString().replace(/\s*$/, '');
|
||||
};
|
||||
function maxWidth(table, theWrap, modifier) {
|
||||
let width = 0;
|
||||
if (!Array.isArray(table)) {
|
||||
table = Object.values(table).map(v => [v]);
|
||||
}
|
||||
table.forEach(v => {
|
||||
width = Math.max(shim.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width);
|
||||
});
|
||||
if (theWrap)
|
||||
width = Math.min(width, parseInt((theWrap * 0.5).toString(), 10));
|
||||
return width;
|
||||
}
|
||||
function normalizeAliases() {
|
||||
const demandedOptions = yargs.getDemandedOptions();
|
||||
const options = yargs.getOptions();
|
||||
(Object.keys(options.alias) || []).forEach(key => {
|
||||
options.alias[key].forEach(alias => {
|
||||
if (descriptions[alias])
|
||||
self.describe(key, descriptions[alias]);
|
||||
if (alias in demandedOptions)
|
||||
yargs.demandOption(key, demandedOptions[alias]);
|
||||
if (options.boolean.includes(alias))
|
||||
yargs.boolean(key);
|
||||
if (options.count.includes(alias))
|
||||
yargs.count(key);
|
||||
if (options.string.includes(alias))
|
||||
yargs.string(key);
|
||||
if (options.normalize.includes(alias))
|
||||
yargs.normalize(key);
|
||||
if (options.array.includes(alias))
|
||||
yargs.array(key);
|
||||
if (options.number.includes(alias))
|
||||
yargs.number(key);
|
||||
});
|
||||
});
|
||||
}
|
||||
let cachedHelpMessage;
|
||||
self.cacheHelpMessage = function () {
|
||||
cachedHelpMessage = this.help();
|
||||
};
|
||||
self.clearCachedHelpMessage = function () {
|
||||
cachedHelpMessage = undefined;
|
||||
};
|
||||
self.hasCachedHelpMessage = function () {
|
||||
return !!cachedHelpMessage;
|
||||
};
|
||||
function addUngroupedKeys(keys, aliases, groups, defaultGroup) {
|
||||
let groupedKeys = [];
|
||||
let toCheck = null;
|
||||
Object.keys(groups).forEach(group => {
|
||||
groupedKeys = groupedKeys.concat(groups[group]);
|
||||
});
|
||||
keys.forEach(key => {
|
||||
toCheck = [key].concat(aliases[key]);
|
||||
if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) {
|
||||
groups[defaultGroup].push(key);
|
||||
}
|
||||
});
|
||||
return groupedKeys;
|
||||
}
|
||||
function filterHiddenOptions(key) {
|
||||
return (yargs.getOptions().hiddenOptions.indexOf(key) < 0 ||
|
||||
yargs.parsed.argv[yargs.getOptions().showHiddenOpt]);
|
||||
}
|
||||
self.showHelp = (level) => {
|
||||
const logger = yargs.getInternalMethods().getLoggerInstance();
|
||||
if (!level)
|
||||
level = 'error';
|
||||
const emit = typeof level === 'function' ? level : logger[level];
|
||||
emit(self.help());
|
||||
};
|
||||
self.functionDescription = fn => {
|
||||
const description = fn.name
|
||||
? shim.Parser.decamelize(fn.name, '-')
|
||||
: __('generated-value');
|
||||
return ['(', description, ')'].join('');
|
||||
};
|
||||
self.stringifiedValues = function stringifiedValues(values, separator) {
|
||||
let string = '';
|
||||
const sep = separator || ', ';
|
||||
const array = [].concat(values);
|
||||
if (!values || !array.length)
|
||||
return string;
|
||||
array.forEach(value => {
|
||||
if (string.length)
|
||||
string += sep;
|
||||
string += JSON.stringify(value);
|
||||
});
|
||||
return string;
|
||||
};
|
||||
function defaultString(value, defaultDescription) {
|
||||
let string = `[${__('default:')} `;
|
||||
if (value === undefined && !defaultDescription)
|
||||
return null;
|
||||
if (defaultDescription) {
|
||||
string += defaultDescription;
|
||||
}
|
||||
else {
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
string += `"${value}"`;
|
||||
break;
|
||||
case 'object':
|
||||
string += JSON.stringify(value);
|
||||
break;
|
||||
default:
|
||||
string += value;
|
||||
}
|
||||
}
|
||||
return `${string}]`;
|
||||
}
|
||||
function windowWidth() {
|
||||
const maxWidth = 80;
|
||||
if (shim.process.stdColumns) {
|
||||
return Math.min(maxWidth, shim.process.stdColumns);
|
||||
}
|
||||
else {
|
||||
return maxWidth;
|
||||
}
|
||||
}
|
||||
let version = null;
|
||||
self.version = ver => {
|
||||
version = ver;
|
||||
};
|
||||
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;
|
||||
failureOutput = false;
|
||||
usages = [];
|
||||
usageDisabled = false;
|
||||
epilogs = [];
|
||||
examples = [];
|
||||
commands = [];
|
||||
descriptions = objFilter(descriptions, k => !localLookup[k]);
|
||||
return self;
|
||||
};
|
||||
const frozens = [];
|
||||
self.freeze = function freeze() {
|
||||
frozens.push({
|
||||
failMessage,
|
||||
failureOutput,
|
||||
usages,
|
||||
usageDisabled,
|
||||
epilogs,
|
||||
examples,
|
||||
commands,
|
||||
descriptions,
|
||||
});
|
||||
};
|
||||
self.unfreeze = function unfreeze(defaultCommand = false) {
|
||||
const frozen = frozens.pop();
|
||||
if (!frozen)
|
||||
return;
|
||||
if (defaultCommand) {
|
||||
descriptions = { ...frozen.descriptions, ...descriptions };
|
||||
commands = [...frozen.commands, ...commands];
|
||||
usages = [...frozen.usages, ...usages];
|
||||
examples = [...frozen.examples, ...examples];
|
||||
epilogs = [...frozen.epilogs, ...epilogs];
|
||||
}
|
||||
else {
|
||||
({
|
||||
failMessage,
|
||||
failureOutput,
|
||||
usages,
|
||||
usageDisabled,
|
||||
epilogs,
|
||||
examples,
|
||||
commands,
|
||||
descriptions,
|
||||
} = frozen);
|
||||
}
|
||||
};
|
||||
return self;
|
||||
}
|
||||
function isIndentedText(text) {
|
||||
return typeof text === 'object';
|
||||
}
|
||||
function addIndentation(text, indent) {
|
||||
return isIndentedText(text)
|
||||
? { text: text.text, indentation: text.indentation + indent }
|
||||
: { text, indentation: indent };
|
||||
}
|
||||
function getIndentation(text) {
|
||||
return isIndentedText(text) ? text.indentation : 0;
|
||||
}
|
||||
function getText(text) {
|
||||
return isIndentedText(text) ? text.text : text;
|
||||
}
|
59
node_modules/yargs/build/lib/utils/apply-extends.js
generated
vendored
59
node_modules/yargs/build/lib/utils/apply-extends.js
generated
vendored
@ -1,59 +0,0 @@
|
||||
import { YError } from '../yerror.js';
|
||||
let previouslyVisitedConfigs = [];
|
||||
let shim;
|
||||
export function applyExtends(config, cwd, mergeExtends, _shim) {
|
||||
shim = _shim;
|
||||
let defaultConfig = {};
|
||||
if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
|
||||
if (typeof config.extends !== 'string')
|
||||
return defaultConfig;
|
||||
const isPath = /\.json|\..*rc$/.test(config.extends);
|
||||
let pathToDefault = null;
|
||||
if (!isPath) {
|
||||
try {
|
||||
pathToDefault = require.resolve(config.extends);
|
||||
}
|
||||
catch (_err) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pathToDefault = getPathToDefaultConfig(cwd, config.extends);
|
||||
}
|
||||
checkForCircularExtends(pathToDefault);
|
||||
previouslyVisitedConfigs.push(pathToDefault);
|
||||
defaultConfig = isPath
|
||||
? JSON.parse(shim.readFileSync(pathToDefault, 'utf8'))
|
||||
: require(config.extends);
|
||||
delete config.extends;
|
||||
defaultConfig = applyExtends(defaultConfig, shim.path.dirname(pathToDefault), mergeExtends, shim);
|
||||
}
|
||||
previouslyVisitedConfigs = [];
|
||||
return mergeExtends
|
||||
? mergeDeep(defaultConfig, config)
|
||||
: Object.assign({}, defaultConfig, config);
|
||||
}
|
||||
function checkForCircularExtends(cfgPath) {
|
||||
if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
|
||||
throw new YError(`Circular extended configurations: '${cfgPath}'.`);
|
||||
}
|
||||
}
|
||||
function getPathToDefaultConfig(cwd, pathToExtend) {
|
||||
return shim.path.resolve(cwd, pathToExtend);
|
||||
}
|
||||
function mergeDeep(config1, config2) {
|
||||
const target = {};
|
||||
function isObject(obj) {
|
||||
return obj && typeof obj === 'object' && !Array.isArray(obj);
|
||||
}
|
||||
Object.assign(target, config1);
|
||||
for (const key of Object.keys(config2)) {
|
||||
if (isObject(config2[key]) && isObject(target[key])) {
|
||||
target[key] = mergeDeep(config1[key], config2[key]);
|
||||
}
|
||||
else {
|
||||
target[key] = config2[key];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
5
node_modules/yargs/build/lib/utils/is-promise.js
generated
vendored
5
node_modules/yargs/build/lib/utils/is-promise.js
generated
vendored
@ -1,5 +0,0 @@
|
||||
export function isPromise(maybePromise) {
|
||||
return (!!maybePromise &&
|
||||
!!maybePromise.then &&
|
||||
typeof maybePromise.then === 'function');
|
||||
}
|
34
node_modules/yargs/build/lib/utils/levenshtein.js
generated
vendored
34
node_modules/yargs/build/lib/utils/levenshtein.js
generated
vendored
@ -1,34 +0,0 @@
|
||||
export function levenshtein(a, b) {
|
||||
if (a.length === 0)
|
||||
return b.length;
|
||||
if (b.length === 0)
|
||||
return a.length;
|
||||
const matrix = [];
|
||||
let i;
|
||||
for (i = 0; i <= b.length; i++) {
|
||||
matrix[i] = [i];
|
||||
}
|
||||
let j;
|
||||
for (j = 0; j <= a.length; j++) {
|
||||
matrix[0][j] = j;
|
||||
}
|
||||
for (i = 1; i <= b.length; i++) {
|
||||
for (j = 1; j <= a.length; j++) {
|
||||
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1];
|
||||
}
|
||||
else {
|
||||
if (i > 1 &&
|
||||
j > 1 &&
|
||||
b.charAt(i - 2) === a.charAt(j - 1) &&
|
||||
b.charAt(i - 1) === a.charAt(j - 2)) {
|
||||
matrix[i][j] = matrix[i - 2][j - 2] + 1;
|
||||
}
|
||||
else {
|
||||
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, Math.min(matrix[i][j - 1] + 1, matrix[i - 1][j] + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return matrix[b.length][a.length];
|
||||
}
|
17
node_modules/yargs/build/lib/utils/maybe-async-result.js
generated
vendored
17
node_modules/yargs/build/lib/utils/maybe-async-result.js
generated
vendored
@ -1,17 +0,0 @@
|
||||
import { isPromise } from './is-promise.js';
|
||||
export function maybeAsyncResult(getResult, resultHandler, errorHandler = (err) => {
|
||||
throw err;
|
||||
}) {
|
||||
try {
|
||||
const result = isFunction(getResult) ? getResult() : getResult;
|
||||
return isPromise(result)
|
||||
? result.then((result) => resultHandler(result))
|
||||
: resultHandler(result);
|
||||
}
|
||||
catch (err) {
|
||||
return errorHandler(err);
|
||||
}
|
||||
}
|
||||
function isFunction(arg) {
|
||||
return typeof arg === 'function';
|
||||
}
|
10
node_modules/yargs/build/lib/utils/obj-filter.js
generated
vendored
10
node_modules/yargs/build/lib/utils/obj-filter.js
generated
vendored
@ -1,10 +0,0 @@
|
||||
import { objectKeys } from '../typings/common-types.js';
|
||||
export function objFilter(original = {}, filter = () => true) {
|
||||
const obj = {};
|
||||
objectKeys(original).forEach(key => {
|
||||
if (filter(key, original[key])) {
|
||||
obj[key] = original[key];
|
||||
}
|
||||
});
|
||||
return obj;
|
||||
}
|
17
node_modules/yargs/build/lib/utils/process-argv.js
generated
vendored
17
node_modules/yargs/build/lib/utils/process-argv.js
generated
vendored
@ -1,17 +0,0 @@
|
||||
function getProcessArgvBinIndex() {
|
||||
if (isBundledElectronApp())
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
function isBundledElectronApp() {
|
||||
return isElectronApp() && !process.defaultApp;
|
||||
}
|
||||
function isElectronApp() {
|
||||
return !!process.versions.electron;
|
||||
}
|
||||
export function hideBin(argv) {
|
||||
return argv.slice(getProcessArgvBinIndex() + 1);
|
||||
}
|
||||
export function getProcessArgvBin() {
|
||||
return process.argv[getProcessArgvBinIndex()];
|
||||
}
|
12
node_modules/yargs/build/lib/utils/set-blocking.js
generated
vendored
12
node_modules/yargs/build/lib/utils/set-blocking.js
generated
vendored
@ -1,12 +0,0 @@
|
||||
export default function setBlocking(blocking) {
|
||||
if (typeof process === 'undefined')
|
||||
return;
|
||||
[process.stdout, process.stderr].forEach(_stream => {
|
||||
const stream = _stream;
|
||||
if (stream._handle &&
|
||||
stream.isTTY &&
|
||||
typeof stream._handle.setBlocking === 'function') {
|
||||
stream._handle.setBlocking(blocking);
|
||||
}
|
||||
});
|
||||
}
|
10
node_modules/yargs/build/lib/utils/which-module.js
generated
vendored
10
node_modules/yargs/build/lib/utils/which-module.js
generated
vendored
@ -1,10 +0,0 @@
|
||||
export default function whichModule(exported) {
|
||||
if (typeof require === 'undefined')
|
||||
return null;
|
||||
for (let i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) {
|
||||
mod = require.cache[files[i]];
|
||||
if (mod.exports === exported)
|
||||
return mod;
|
||||
}
|
||||
return null;
|
||||
}
|
305
node_modules/yargs/build/lib/validation.js
generated
vendored
305
node_modules/yargs/build/lib/validation.js
generated
vendored
@ -1,305 +0,0 @@
|
||||
import { argsert } from './argsert.js';
|
||||
import { assertNotStrictEqual, } from './typings/common-types.js';
|
||||
import { levenshtein as distance } from './utils/levenshtein.js';
|
||||
import { objFilter } from './utils/obj-filter.js';
|
||||
const specialKeys = ['$0', '--', '_'];
|
||||
export function validation(yargs, usage, shim) {
|
||||
const __ = shim.y18n.__;
|
||||
const __n = shim.y18n.__n;
|
||||
const self = {};
|
||||
self.nonOptionCount = function nonOptionCount(argv) {
|
||||
const demandedCommands = yargs.getDemandedCommands();
|
||||
const positionalCount = argv._.length + (argv['--'] ? argv['--'].length : 0);
|
||||
const _s = positionalCount - yargs.getInternalMethods().getContext().commands.length;
|
||||
if (demandedCommands._ &&
|
||||
(_s < demandedCommands._.min || _s > demandedCommands._.max)) {
|
||||
if (_s < demandedCommands._.min) {
|
||||
if (demandedCommands._.minMsg !== undefined) {
|
||||
usage.fail(demandedCommands._.minMsg
|
||||
? demandedCommands._.minMsg
|
||||
.replace(/\$0/g, _s.toString())
|
||||
.replace(/\$1/, demandedCommands._.min.toString())
|
||||
: null);
|
||||
}
|
||||
else {
|
||||
usage.fail(__n('Not enough non-option arguments: got %s, need at least %s', 'Not enough non-option arguments: got %s, need at least %s', _s, _s.toString(), demandedCommands._.min.toString()));
|
||||
}
|
||||
}
|
||||
else if (_s > demandedCommands._.max) {
|
||||
if (demandedCommands._.maxMsg !== undefined) {
|
||||
usage.fail(demandedCommands._.maxMsg
|
||||
? demandedCommands._.maxMsg
|
||||
.replace(/\$0/g, _s.toString())
|
||||
.replace(/\$1/, demandedCommands._.max.toString())
|
||||
: null);
|
||||
}
|
||||
else {
|
||||
usage.fail(__n('Too many non-option arguments: got %s, maximum of %s', 'Too many non-option arguments: got %s, maximum of %s', _s, _s.toString(), demandedCommands._.max.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
self.positionalCount = function positionalCount(required, observed) {
|
||||
if (observed < required) {
|
||||
usage.fail(__n('Not enough non-option arguments: got %s, need at least %s', 'Not enough non-option arguments: got %s, need at least %s', observed, observed + '', required + ''));
|
||||
}
|
||||
};
|
||||
self.requiredArguments = function requiredArguments(argv, demandedOptions) {
|
||||
let missing = null;
|
||||
for (const key of Object.keys(demandedOptions)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(argv, key) ||
|
||||
typeof argv[key] === 'undefined') {
|
||||
missing = missing || {};
|
||||
missing[key] = demandedOptions[key];
|
||||
}
|
||||
}
|
||||
if (missing) {
|
||||
const customMsgs = [];
|
||||
for (const key of Object.keys(missing)) {
|
||||
const msg = missing[key];
|
||||
if (msg && customMsgs.indexOf(msg) < 0) {
|
||||
customMsgs.push(msg);
|
||||
}
|
||||
}
|
||||
const customMsg = customMsgs.length ? `\n${customMsgs.join('\n')}` : '';
|
||||
usage.fail(__n('Missing required argument: %s', 'Missing required arguments: %s', Object.keys(missing).length, Object.keys(missing).join(', ') + customMsg));
|
||||
}
|
||||
};
|
||||
self.unknownArguments = function unknownArguments(argv, aliases, positionalMap, isDefaultCommand, checkPositionals = true) {
|
||||
var _a;
|
||||
const commandKeys = yargs
|
||||
.getInternalMethods()
|
||||
.getCommandInstance()
|
||||
.getCommands();
|
||||
const unknown = [];
|
||||
const currentContext = yargs.getInternalMethods().getContext();
|
||||
Object.keys(argv).forEach(key => {
|
||||
if (!specialKeys.includes(key) &&
|
||||
!Object.prototype.hasOwnProperty.call(positionalMap, key) &&
|
||||
!Object.prototype.hasOwnProperty.call(yargs.getInternalMethods().getParseContext(), key) &&
|
||||
!self.isValidAndSomeAliasIsNotNew(key, aliases)) {
|
||||
unknown.push(key);
|
||||
}
|
||||
});
|
||||
if (checkPositionals &&
|
||||
(currentContext.commands.length > 0 ||
|
||||
commandKeys.length > 0 ||
|
||||
isDefaultCommand)) {
|
||||
argv._.slice(currentContext.commands.length).forEach(key => {
|
||||
if (!commandKeys.includes('' + key)) {
|
||||
unknown.push('' + key);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (checkPositionals) {
|
||||
const demandedCommands = yargs.getDemandedCommands();
|
||||
const maxNonOptDemanded = ((_a = demandedCommands._) === null || _a === void 0 ? void 0 : _a.max) || 0;
|
||||
const expected = currentContext.commands.length + maxNonOptDemanded;
|
||||
if (expected < argv._.length) {
|
||||
argv._.slice(expected).forEach(key => {
|
||||
key = String(key);
|
||||
if (!currentContext.commands.includes(key) &&
|
||||
!unknown.includes(key)) {
|
||||
unknown.push(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (unknown.length) {
|
||||
usage.fail(__n('Unknown argument: %s', 'Unknown arguments: %s', unknown.length, unknown.map(s => (s.trim() ? s : `"${s}"`)).join(', ')));
|
||||
}
|
||||
};
|
||||
self.unknownCommands = function unknownCommands(argv) {
|
||||
const commandKeys = yargs
|
||||
.getInternalMethods()
|
||||
.getCommandInstance()
|
||||
.getCommands();
|
||||
const unknown = [];
|
||||
const currentContext = yargs.getInternalMethods().getContext();
|
||||
if (currentContext.commands.length > 0 || commandKeys.length > 0) {
|
||||
argv._.slice(currentContext.commands.length).forEach(key => {
|
||||
if (!commandKeys.includes('' + key)) {
|
||||
unknown.push('' + key);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (unknown.length > 0) {
|
||||
usage.fail(__n('Unknown command: %s', 'Unknown commands: %s', unknown.length, unknown.join(', ')));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
self.isValidAndSomeAliasIsNotNew = function isValidAndSomeAliasIsNotNew(key, aliases) {
|
||||
if (!Object.prototype.hasOwnProperty.call(aliases, key)) {
|
||||
return false;
|
||||
}
|
||||
const newAliases = yargs.parsed.newAliases;
|
||||
return [key, ...aliases[key]].some(a => !Object.prototype.hasOwnProperty.call(newAliases, a) || !newAliases[key]);
|
||||
};
|
||||
self.limitedChoices = function limitedChoices(argv) {
|
||||
const options = yargs.getOptions();
|
||||
const invalid = {};
|
||||
if (!Object.keys(options.choices).length)
|
||||
return;
|
||||
Object.keys(argv).forEach(key => {
|
||||
if (specialKeys.indexOf(key) === -1 &&
|
||||
Object.prototype.hasOwnProperty.call(options.choices, key)) {
|
||||
[].concat(argv[key]).forEach(value => {
|
||||
if (options.choices[key].indexOf(value) === -1 &&
|
||||
value !== undefined) {
|
||||
invalid[key] = (invalid[key] || []).concat(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
const invalidKeys = Object.keys(invalid);
|
||||
if (!invalidKeys.length)
|
||||
return;
|
||||
let msg = __('Invalid values:');
|
||||
invalidKeys.forEach(key => {
|
||||
msg += `\n ${__('Argument: %s, Given: %s, Choices: %s', key, usage.stringifiedValues(invalid[key]), usage.stringifiedValues(options.choices[key]))}`;
|
||||
});
|
||||
usage.fail(msg);
|
||||
};
|
||||
let implied = {};
|
||||
self.implies = function implies(key, value) {
|
||||
argsert('<string|object> [array|number|string]', [key, value], arguments.length);
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(k => {
|
||||
self.implies(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
yargs.global(key);
|
||||
if (!implied[key]) {
|
||||
implied[key] = [];
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(i => self.implies(key, i));
|
||||
}
|
||||
else {
|
||||
assertNotStrictEqual(value, undefined, shim);
|
||||
implied[key].push(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
self.getImplied = function getImplied() {
|
||||
return implied;
|
||||
};
|
||||
function keyExists(argv, val) {
|
||||
const num = Number(val);
|
||||
val = isNaN(num) ? val : num;
|
||||
if (typeof val === 'number') {
|
||||
val = argv._.length >= val;
|
||||
}
|
||||
else if (val.match(/^--no-.+/)) {
|
||||
val = val.match(/^--no-(.+)/)[1];
|
||||
val = !Object.prototype.hasOwnProperty.call(argv, val);
|
||||
}
|
||||
else {
|
||||
val = Object.prototype.hasOwnProperty.call(argv, val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
self.implications = function implications(argv) {
|
||||
const implyFail = [];
|
||||
Object.keys(implied).forEach(key => {
|
||||
const origKey = key;
|
||||
(implied[key] || []).forEach(value => {
|
||||
let key = origKey;
|
||||
const origValue = value;
|
||||
key = keyExists(argv, key);
|
||||
value = keyExists(argv, value);
|
||||
if (key && !value) {
|
||||
implyFail.push(` ${origKey} -> ${origValue}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (implyFail.length) {
|
||||
let msg = `${__('Implications failed:')}\n`;
|
||||
implyFail.forEach(value => {
|
||||
msg += value;
|
||||
});
|
||||
usage.fail(msg);
|
||||
}
|
||||
};
|
||||
let conflicting = {};
|
||||
self.conflicts = function conflicts(key, value) {
|
||||
argsert('<string|object> [array|string]', [key, value], arguments.length);
|
||||
if (typeof key === 'object') {
|
||||
Object.keys(key).forEach(k => {
|
||||
self.conflicts(k, key[k]);
|
||||
});
|
||||
}
|
||||
else {
|
||||
yargs.global(key);
|
||||
if (!conflicting[key]) {
|
||||
conflicting[key] = [];
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(i => self.conflicts(key, i));
|
||||
}
|
||||
else {
|
||||
conflicting[key].push(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
self.getConflicting = () => conflicting;
|
||||
self.conflicting = function conflictingFn(argv) {
|
||||
Object.keys(argv).forEach(key => {
|
||||
if (conflicting[key]) {
|
||||
conflicting[key].forEach(value => {
|
||||
if (value && argv[key] !== undefined && argv[value] !== undefined) {
|
||||
usage.fail(__('Arguments %s and %s are mutually exclusive', key, value));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
if (yargs.getInternalMethods().getParserConfiguration()['strip-dashed']) {
|
||||
Object.keys(conflicting).forEach(key => {
|
||||
conflicting[key].forEach(value => {
|
||||
if (value &&
|
||||
argv[shim.Parser.camelCase(key)] !== undefined &&
|
||||
argv[shim.Parser.camelCase(value)] !== undefined) {
|
||||
usage.fail(__('Arguments %s and %s are mutually exclusive', key, value));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
self.recommendCommands = function recommendCommands(cmd, potentialCommands) {
|
||||
const threshold = 3;
|
||||
potentialCommands = potentialCommands.sort((a, b) => b.length - a.length);
|
||||
let recommended = null;
|
||||
let bestDistance = Infinity;
|
||||
for (let i = 0, candidate; (candidate = potentialCommands[i]) !== undefined; i++) {
|
||||
const d = distance(cmd, candidate);
|
||||
if (d <= threshold && d < bestDistance) {
|
||||
bestDistance = d;
|
||||
recommended = candidate;
|
||||
}
|
||||
}
|
||||
if (recommended)
|
||||
usage.fail(__('Did you mean %s?', recommended));
|
||||
};
|
||||
self.reset = function reset(localLookup) {
|
||||
implied = objFilter(implied, k => !localLookup[k]);
|
||||
conflicting = objFilter(conflicting, k => !localLookup[k]);
|
||||
return self;
|
||||
};
|
||||
const frozens = [];
|
||||
self.freeze = function freeze() {
|
||||
frozens.push({
|
||||
implied,
|
||||
conflicting,
|
||||
});
|
||||
};
|
||||
self.unfreeze = function unfreeze() {
|
||||
const frozen = frozens.pop();
|
||||
assertNotStrictEqual(frozen, undefined, shim);
|
||||
({ implied, conflicting } = frozen);
|
||||
};
|
||||
return self;
|
||||
}
|
1512
node_modules/yargs/build/lib/yargs-factory.js
generated
vendored
1512
node_modules/yargs/build/lib/yargs-factory.js
generated
vendored
File diff suppressed because it is too large
Load Diff
9
node_modules/yargs/build/lib/yerror.js
generated
vendored
9
node_modules/yargs/build/lib/yerror.js
generated
vendored
@ -1,9 +0,0 @@
|
||||
export class YError extends Error {
|
||||
constructor(msg) {
|
||||
super(msg || 'yargs error');
|
||||
this.name = 'YError';
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, YError);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user