- Prompt / Ask a question to the user
- Hide the input characters for sensible infos
const sh = require('kool-shell')
function yesNoQuestion(answer) {
return answer === '' || answer.match(/^y(es)?$/i)
}
sh.input('Do you like omelette du fromage? (Yes)', {
onSubmit: yesNoQuestion
})
.then(omeletteLover => {
if (omeletteLover) console.log('Nice. I like it too.')
})
Ask label
to the user.
Resume the process.stdin input stream and wait for the user answer.
Return a promise that will be resolved with the answer, when the user has answered.
label
(String): A statement or query to write to the console, prepended to the prompt.options
(Object)hidden
(Boolean, default false): Hide the user input with the*
char. This is useful for sensible data like passwords.onSubmit
: (Function): A function that will be called when the user has answered. You can return a simple value or a promise if you want to do asynchronous actions. The input will resolve with the return value from the onSubmit function. If you reject your onSubmit promise,sh.input
will be rejected as well. TheonSubmit
option can be useful to avoid too much nested promises or to process the user answer before resolvingsh.input
.