import {TerminalInput} from './TerminalInput'; const yes = ['y', 'yes']; const no = ['n', 'no']; const validate = (value: string) => ( yes.includes(value.toLowerCase()) || no.includes(value.toLowerCase()) ); const getHint = (value: string) => { if (value && !validate(value)) { return 'Enter yes or no (y/n)'; } return ''; }; export namespace TerminalConfirm { export async function ask(question: string, noPrompt?: boolean, answer?: boolean, hint: string = '') { if (noPrompt) { const yesOrNo = answer ? 'yes' : 'no'; console.info(`${question}: ${yesOrNo}`); return answer; } const result = await TerminalInput.ask(question, { getHint: (value) => getHint(value) || hint, validate, clearOnInvalidInput: true }); return yes.includes(result.toLowerCase()); } }