mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 23:28:39 +08:00
feat(backend): Add tab-completion to server console command names
This commit is contained in:
parent
ecb997885c
commit
e1e76c6be7
@ -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
|
||||
};
|
||||
};
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user