26 lines
528 B
JavaScript
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!`);
|
|
}
|
|
}
|