aboutsummaryrefslogtreecommitdiff
path: root/node_modules/yargs/build/lib/argsert.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-04-17 17:37:10 +0200
committerMinteck <contact@minteck.org>2022-04-17 17:37:10 +0200
commit4081c2036a5af21519095da1b8b99c507b0fba93 (patch)
treefc95894e74c84d4d34c0d761837e8d6175829dd7 /node_modules/yargs/build/lib/argsert.js
parent637ca7ba746c0241aaec79b79349d5dac4ec7408 (diff)
downloadtwilight-4081c2036a5af21519095da1b8b99c507b0fba93.tar.gz
twilight-4081c2036a5af21519095da1b8b99c507b0fba93.tar.bz2
twilight-4081c2036a5af21519095da1b8b99c507b0fba93.zip
Deprecation
Diffstat (limited to 'node_modules/yargs/build/lib/argsert.js')
-rw-r--r--node_modules/yargs/build/lib/argsert.js62
1 files changed, 0 insertions, 62 deletions
diff --git a/node_modules/yargs/build/lib/argsert.js b/node_modules/yargs/build/lib/argsert.js
deleted file mode 100644
index be5b3aa..0000000
--- a/node_modules/yargs/build/lib/argsert.js
+++ /dev/null
@@ -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}.`);
-}