diff --git a/src/utils/confirm.ts b/src/utils/confirm.ts new file mode 100644 index 0000000..0e56376 --- /dev/null +++ b/src/utils/confirm.ts @@ -0,0 +1,26 @@ +import prompts from 'prompts'; + +export interface IConfirmOptions { + confirm?: boolean; + fail?: boolean; +} + +export default async function confirm( + message: string, + options: IConfirmOptions = {} +): Promise { + if (!options.confirm) return true; + + const response = await prompts({ + type: 'confirm', + name: 'value', + message: message, + initial: true + }); + + if (!response.value) { + if (options.fail) throw Error(`Cancelled by user`); + return false; + } + return true; +}