REPL completion

responsive-workspace-demoday
Fabien Benetou 2 years ago
parent 28c5b31e2d
commit 386416094b
  1. 41
      index.js

@ -278,6 +278,7 @@ app.get('/sshconfig', (req, res) => {
// note that stopping this process removes the mounts // note that stopping this process removes the mounts
function mountAll(){ function mountAll(){
// might have to scanpeers() first // might have to scanpeers() first
if (foundPeers.length==0) return
getSshConfig().map( l => { getSshConfig().map( l => {
let cs = 'sshfs ' + l.name + ':' let cs = 'sshfs ' + l.name + ':'
if (l.custom) if (l.custom)
@ -382,19 +383,29 @@ const webServer = https.createServer(credentials, app);
// const webServer = http.createServer(app); // const webServer = http.createServer(app);
// Listen on port // Listen on port
webServer.listen(port, () => { webServer.listen(port, () => {
console.log("listening on "+protocol+"://localhost:" + port); console.log("listening on "+protocol+"://localhost:" + port)
getCommand()
}); });
// REPL testing // REPL testing
const readline = require("readline"); const readline = require("readline");
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout output: process.stdout,
completer: completer
}); });
// https://nodejs.org/api/readline.html#use-of-the-completer-function
function completer(line) {
const completions = help().split('\n');
const hits = completions.filter((c) => c.startsWith(line));
// Show all completions if none found
return [hits.length ? hits : completions, line];
}
let command = '' let command = ''
function getCommand(){ function getCommand(){
rl.question("REPL: ", function(command) { rl.question(process.title+" REPL: ", function(command) {
if (command == "close") { if (command == "close") {
rl.close(); rl.close();
} else { } else {
@ -408,7 +419,6 @@ function getCommand(){
} }
}); });
} }
getCommand()
function help(){ function help(){
return ` return `
@ -416,7 +426,28 @@ help()
execConfiguredCommand(cmdName) execConfiguredCommand(cmdName)
getSshConfig() getSshConfig()
mountAll() mountAll()
scanpeers()` scanpeers()
foundPeers
port
protocol
subclass
publicKeyPath
publicKey
md5fromPub
process.title
filename
fileSaveFullPath
minfilename
minfileSaveFullPath
sshconfigpath
propath
localServices
configFilePath
utilsCmd
instructions
auth_instructions
process.title
`
} }
rl.on("close", function() { rl.on("close", function() {

Loading…
Cancel
Save