Inquirer.js
Inquirer.js copied to clipboard
Allow questions can be marked as mandatory
releated issue: https://github.com/SBoudrias/Inquirer.js/issues/1091
options = {
things: {
message: 'App name?',
type: 'input',
required: true
}
};
If a user does not provide a non-empty app name, keep asking the same question.
Today you can use the validate function for this, check the input and make sure there is content; if not return an error message.
I'm leaning towards not augmenting the API with this extra option because:
requiredwould only work oninputtype prompt- We'd need to decided how to handle getting both
requiredandvalidateon that prompt - This add an extra internal content that isn't translated; and this has been a recurring issue for international users of the library.
I'm revising my opinion in 2024. I'd be happy to add a required property to the new @inquirer/input - with similar implementation to the same option on the checkbox prompt: https://github.com/SBoudrias/Inquirer.js/tree/master/packages/checkbox