2025-11-25 03:42:12 +01:00
|
|
|
import { stdin as input, stdout as output } from "node:process";
|
2025-11-25 12:12:13 +01:00
|
|
|
import readline from "node:readline/promises";
|
2025-11-25 03:42:12 +01:00
|
|
|
|
|
|
|
|
import { isVerbose, isYes } from "../globals.js";
|
|
|
|
|
|
2026-01-14 14:31:43 +00:00
|
|
|
export async function promptYesNo(question: string, defaultYes = false): Promise<boolean> {
|
2025-11-26 00:53:53 +01:00
|
|
|
// Simple Y/N prompt honoring global --yes and verbosity flags.
|
|
|
|
|
if (isVerbose() && isYes()) return true; // redundant guard when both flags set
|
|
|
|
|
if (isYes()) return true;
|
|
|
|
|
const rl = readline.createInterface({ input, output });
|
|
|
|
|
const suffix = defaultYes ? " [Y/n] " : " [y/N] ";
|
2026-01-14 14:31:43 +00:00
|
|
|
const answer = (await rl.question(`${question}${suffix}`)).trim().toLowerCase();
|
2025-11-26 00:53:53 +01:00
|
|
|
rl.close();
|
|
|
|
|
if (!answer) return defaultYes;
|
|
|
|
|
return answer.startsWith("y");
|
2025-11-25 03:42:12 +01:00
|
|
|
}
|