UNPKG

ernest

Version:

Web framework for HTTP and HTTPS, using ExpressJS, Session, Mongo, Socket IO, Redis

121 lines (111 loc) 2.52 kB
const Ernest_Commands = require('./Ernest_Commands'); const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout,completer }); class Ernest_show { constructor(ernest,logPath) { this.ernestCommand = new Ernest_Commands(ernest,logPath,function(message,callback) { rl.question(message + " ", (answer) => { callback(answer); }); },function(text) { console.log(text); }); }; MainMenu() { this.ernestCommand.MainMenu(); }; }; module.exports = Ernest_show; function completer(line) { var completions = []; completions.push('addPagetoUser'); completions.push('addUser'); completions.push('adminCommand'); completions.push('clear'); completions.push('collectionExist'); completions.push('Collections'); completions.push('CopyPublicFile'); completions.push('createCollection'); completions.push('CreatePublicAccess'); completions.push('db'); completions.push('DB_Backup'); completions.push('DB_Restore'); completions.push('dbCommand'); completions.push('deleteCollection'); completions.push('deleteUser'); completions.push('deleteUserProperty'); completions.push('exit'); completions.push('IsPublicAccess'); completions.push('ListPublicFiles'); completions.push('log'); completions.push('logs'); completions.push('man'); completions.push('onUser'); completions.push('outUser'); completions.push('pid'); completions.push('reloadREST'); completions.push('removePageUser'); completions.push('rsStatus'); completions.push('serverStatus'); completions.push('setdb'); completions.push('SetPublicAccess'); completions.push('showUser'); completions.push('status'); completions.push('UnSetPublicAccess'); completions.push('updateUserPassword'); completions.push('updateUserProperties'); if(line.charAt(0)== "/") { var lp = getLastPossible(line); var filescompletions = fs.readdirSync(lp); var arr = filescompletions.map(i => lp + i); var files = arr.filter(function(c) { if (c.indexOf(line) == 0) { return c; } }); return [files, line]; } else { var hits = completions.filter(function(c) { if (c.indexOf(line) == 0) { return c; } }); return [hits && hits.length ? hits : completions, line]; }; } function getLastPossible(line) { if(line.length > 1) { let lio = line.lastIndexOf("/"); if(lio == 0) { return "/"; } else { return line.substr(0,lio +1); }; } else { return "/"; }; }