Skip to content

Commit

Permalink
feat(utils): adds confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 29, 2019
1 parent 98d3474 commit fc40be3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/utils/confirm.ts
Original file line number Diff line number Diff line change
@@ -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<boolean> {
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;
}

0 comments on commit fc40be3

Please sign in to comment.