Files
OmniRoute/bin/cli/io.mjs
diegosouzapw bbecbccb0a fix(cli): harden setup, doctor, and backup workflows
Hide admin password entry during setup, make doctor degrade to warnings
when source-only runtime checks are unavailable, and improve stop
behavior by attempting graceful shutdown before force killing ports.

Also use SQLite's backup API for safer snapshots under WAL, align CLI
key writes with the current provider_connections schema, and include
follow-on compatibility fixes for GLM provider detection, stream error
sanitization, and auth-aware test coverage.
2026-05-11 09:13:49 -03:00

57 lines
1.4 KiB
JavaScript

import readline from "node:readline";
export function createPrompt() {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function ask(question, defaultValue = "") {
const suffix = defaultValue ? ` (${defaultValue})` : "";
return new Promise((resolve) => {
rl.question(`${question}${suffix}: `, (answer) => {
const trimmed = answer.trim();
resolve(trimmed || defaultValue);
});
});
}
function askSecret(question) {
return new Promise((resolve) => {
let prompted = false;
const saved = rl._writeToOutput.bind(rl);
rl._writeToOutput = function (str) {
if (!prompted) {
rl.output.write(str);
if (str.endsWith(": ")) prompted = true;
return;
}
// Suppress character echo; allow only newlines through
if (str === "\r\n" || str === "\n" || str === "\r") rl.output.write("\n");
};
rl.question(`${question}: `, (answer) => {
rl._writeToOutput = saved;
resolve(answer.trim());
});
});
}
function close() {
rl.close();
}
return { ask, askSecret, close };
}
export function printHeading(title) {
console.log(`\n\x1b[1m\x1b[36m${title}\x1b[0m\n`);
}
export function printSuccess(message) {
console.log(`\x1b[32m✔ ${message}\x1b[0m`);
}
export function printInfo(message) {
console.log(`\x1b[2m${message}\x1b[0m`);
}