l7note
Version:
Access your notion notes quick
75 lines (60 loc) • 1.42 kB
text/typescript
import { argv } from 'process';
import { globalConfig, RunType } from './setup.js';
const parseCliArgs = () => {
//Remove node args
let args = argv.slice(2);
if (args.length == 0) {
globalConfig.runType = RunType.LIST;
globalConfig.optionalArgs = [];
return;
}
//save and remove mode
let modus = args[0].toLowerCase();
args = args.slice(1);
if (args.length == 0) {
globalConfig.optionalArgs = [];
} else {
//Seperate at every -
args = args.join(' ').split(/(?=\-)/);
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':
globalConfig.runType = RunType.LIST;
break;
case 'a':
case 'add':
globalConfig.runType = RunType.ADD;
break;
case 'r':
case 'remove':
globalConfig.runType = RunType.REMOVE;
break;
case 'c':
case 'config':
globalConfig.runType = RunType.CONFIG;
break;
case 'reset':
globalConfig.runType = RunType.RESET;
break;
case '?':
case 'h':
case 'help':
globalConfig.runType = RunType.HELP;
break;
default:
globalConfig.runType = RunType.EXTRA;
break;
}
};
export { parseCliArgs };