absenat
Version:
dedicated messaging service core
42 lines (41 loc) • 1.1 kB
JavaScript
/**
* @author mr-exception
* @description In this file, all commands designed as a command line interface are loaded for the user. Its primary responsibility is to retrieve command text from the command line and transfer it to the corresponding method.
*/
const standard_input = process.stdin;
standard_input.setEncoding('utf-8');
const readline = require('readline').createInterface({
input: standard_input,
output: process.stdout
});
/**
* finshes current comannd and starts a new line
*/
const finished = () => {
readline.question(`# `, command => {
run_command(command);
});
}
const run_command = input => {
let args = input.replace('\n', '').split(' ');
const command = args[0];
args.splice(0, 1)
if (!command_functions[command]) {
console.log(chalk.red(`Err: Command ${command} not found.`));
finished();
} else
command_functions[command](args, () => {
finished();
});
}
/**
* starts the command line interface with *commands* array
* @param {array} commands
*/
const run = () => {
finished();
}
module.exports = {
run,
finished,
}