Skip to content

Commit 527ce8d

Browse files
authored
refactor: use inquirer to implement CLI.prompt (#310)
1 parent 08d3a5f commit 527ce8d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/cli.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ const ora = require('ora');
44
const { EOL } = require('os');
55
const chalk = require('chalk');
66
const read = require('read');
7-
const { IGNORE } = require('./run');
7+
const inquirer = require('inquirer');
88

9+
const { IGNORE } = require('./run');
910
const { warning, error, info, success } = require('./figures');
11+
1012
const FIGURE_INDENT = ' ';
1113
const EOL_INDENT = `${EOL}${FIGURE_INDENT}`;
1214

@@ -47,19 +49,14 @@ class CLI {
4749
}
4850

4951
async prompt(question, defaultAnswer = true) {
50-
const option =
51-
`[${(defaultAnswer ? 'Y' : 'y')}/${(defaultAnswer ? 'n' : 'N')}]`;
5252
this.separator();
53-
const promptText = `${chalk.bold.cyan('?')} ${question} ${option} `;
54-
55-
const answer = await this.promptForInput(promptText);
56-
const trimmed = answer.toLowerCase().trim();
57-
if (!trimmed) {
58-
return defaultAnswer;
59-
} else if (trimmed === 'y') {
60-
return true;
61-
}
62-
return false;
53+
const { answer } = await inquirer.prompt([{
54+
type: 'confirm',
55+
name: 'answer',
56+
message: question,
57+
default: defaultAnswer
58+
}]);
59+
return answer;
6360
}
6461

6562
startSpinner(text) {

0 commit comments

Comments
 (0)