I'm using Inquirer.js to create a CLI's prompter
which allows users
to enter/reply to some input/questions. In the last question, I want to add a feature that if the user
replies no
to Are you done?
question, then the prompter
will restart asking the questions until the user
replies yes
. I'm almost there with the functionality.
It's working, but only on the first time when I enter no
. The second time I enter no
, the prompter stops.
How can I run this on a loop to accomplish the desired behavior? What I'm doing wrong?
This is what I have some far:
import inquirer from 'inquirer';
inquirer
.prompt([
// { bunch of other questions previously },
{
type: 'confirm',
name: 'repeat_questions',
message: 'Are you done?',
},
])
.then((answers) => {
if (answers.repeat_questions) {
return inquirer.prompt([
// { bunch of other questions previously },
{
type: 'confirm',
name: 'repeat_questions',
message: 'Are you done?',
},
]);
}
})
.catch((error) => {
if (error.isTtyError) {
throw new Error(`Prompt couldn't be render in current environment`);
}
});