1
0
Fork 0
gallery-dl-archive-manager/args.js
2024-02-09 17:27:51 -05:00

26 lines
528 B
JavaScript

let argRegex = new RegExp('(\-\-[a-zA-Z0-9]+)(=)(.*)');
const parseArgs = () => {
let _args = { '_': [] };
[...process.argv.slice(2)].forEach(arg => {
let result = argRegex.exec(arg);
if (!!result) {
_args[result[1].replace('--','')] = result[3];
} else {
_args['_'].push(arg);
}
});
return _args;
}
export const args = parseArgs();
export const getArg = (argName) => {
let arg = args[argName];
if (!!arg) {
return arg;
} else {
throw(`${argName} was not supplied!`);
}
}