l7note
Version:
Access your notion notes quick
66 lines (65 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCliArgs = void 0;
const process_1 = require("process");
const setup_js_1 = require("./setup.js");
const parseCliArgs = () => {
//Remove node args
let args = process_1.argv.slice(2);
if (args.length == 0) {
setup_js_1.globalConfig.runType = setup_js_1.RunType.LIST;
setup_js_1.globalConfig.optionalArgs = [];
return;
}
//save and remove mode
let modus = args[0].toLowerCase();
args = args.slice(1);
if (args.length == 0) {
setup_js_1.globalConfig.optionalArgs = [];
}
else {
//Seperate at every -
args = args.join(' ').split(/(?=\-)/);
setup_js_1.globalConfig.optionalArgs = args.map(arg => {
const name = arg.substring(0, 2);
if (name[0] == '-') {
const value = arg.slice(2).trim();
return { name, value };
}
else {
const value = arg.trim();
return { name: '-h', value };
}
});
}
switch (modus) {
case 'l':
case 'list':
setup_js_1.globalConfig.runType = setup_js_1.RunType.LIST;
break;
case 'a':
case 'add':
setup_js_1.globalConfig.runType = setup_js_1.RunType.ADD;
break;
case 'r':
case 'remove':
setup_js_1.globalConfig.runType = setup_js_1.RunType.REMOVE;
break;
case 'c':
case 'config':
setup_js_1.globalConfig.runType = setup_js_1.RunType.CONFIG;
break;
case 'reset':
setup_js_1.globalConfig.runType = setup_js_1.RunType.RESET;
break;
case '?':
case 'h':
case 'help':
setup_js_1.globalConfig.runType = setup_js_1.RunType.HELP;
break;
default:
setup_js_1.globalConfig.runType = setup_js_1.RunType.EXTRA;
break;
}
};
exports.parseCliArgs = parseCliArgs;