define(repl: ReplContext,commands: Record<string, ReplCommand>): void
Registers commands on the server under their own names and every alias.
Three things happen here rather than in all thirty-seven commands, because all thirty-seven wanted them and any that forgot one was a bug:
clearBufferedCommand()first.node:replneeds it before a command's output, and without it the output landed in a half-drawn line.- The prompt afterwards.
node:replredraws after a SYNCHRONOUS command and nothing else, so every async one had to remember to draw its own — which is why they all ended in the same line, and why forgetting it left a terminal with no prompt. - A
catcharound the lot.node:replcannot await an action, so the promise is floated — but caught. A command that rejects has failed, which is a line of output; unhandled, it is Node killing the session over one bad.doc.
import { define } from './command.ts'; import type { ReplContext } from './command.ts'; // Defined, not invoked: it writes to a live prompt. function example(repl: ReplContext) { define(repl, { pwd: { description: 'Where you are', main: (it) => it.log(it.cwd) } }); }
repl: ReplContext
commands: Record<string, ReplCommand>