feat(backend): Add tab-completion to server console command names

This commit is contained in:
Sam Atkins 2024-06-28 11:48:45 +01:00 committed by Eric Dubé
parent ecb997885c
commit e1e76c6be7
2 changed files with 19 additions and 1 deletions

View File

@ -23,6 +23,10 @@ class Command {
this.spec_ = spec;
}
get id() {
return this.spec_.id;
}
async execute(args, log) {
log = log ?? console;
const { id, name, description, handler } = this.spec_;
@ -79,8 +83,12 @@ class CommandService extends BaseService {
const args = text.split(/\s+/);
await this.executeCommand(args, log);
}
get commandNames() {
return this.commands_.map(command => command.id);
}
}
module.exports = {
CommandService
};
};

View File

@ -131,6 +131,16 @@ class DevConsoleService extends BaseService {
output: process.stdout,
prompt: 'puter> ',
terminal: true,
completer: line => {
// We only complete service and command names
if ( line.includes(' ') )
return;
const results = commands.commandNames
.filter(name => name.startsWith(line))
.map(name => `${name} `); // Add a space after to make typing arguments more convenient
return [ results, line ];
},
});
rl.on('line', async (input) => {
this._before_cmd();