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
function mountAll(){
// might have to scanpeers() first
if (foundPeers.length==0) return
getSshConfig().map( l => {
let cs = 'sshfs ' + l.name + ':'
if (l.custom)
@ -382,19 +383,29 @@ const webServer = https.createServer(credentials, app);
// const webServer = http.createServer(app);
// Listen on port
webServer.listen(port, () => {
console.log("listening on "+protocol+"://localhost:" + port);
console.log("listening on "+protocol+"://localhost:" + port)
getCommand()
});
// REPL testing
const readline = require("readline");
const rl = readline.createInterface({
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 = ''
function getCommand(){
rl.question("REPL: ", function(command) {
rl.question(process.title+" REPL: ", function(command) {
if (command == "close") {
rl.close();
} else {
@ -408,7 +419,6 @@ function getCommand(){
}
});
}
getCommand()
function help(){
return `
@ -416,7 +426,28 @@ help()
execConfiguredCommand(cmdName)
getSshConfig()
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() {

Loading…
Cancel
Save