Todd
A minimalistic helper library for making cli apps.
Todd has been named after the Breaking Bad character. Todd is a simple guy (or library in this case), he just asks some questions and gets things done.
Installation
npm i --save todd
There are 2 ways you can use todd, either with callbacks or with promises.
Usage with callbacks
Callbacks are ideal, if you don't want to perform extra checks for the response given. The callback will be called directly if the matching option was typed in the console.
ask something with fixed answers (options)
; ;
this will produce the following prompt:
Do you really want us coming back mrs. White?
1) Get out, leave us alone!
2) I think Junior wants breakfast.
Choose one of the options and hit Enter
if you choose an answer that Todd doesn't understand, Todd will repeat the question.
Do you really want us coming back mrs. White?
1) Get out, leave us alone!
2) I think Junior wants breakfast.
Choose one of the options and hit Enter
3
I didn't quite get that.
Do you really want us coming back mrs. White?
1) Get out, leave us alone!
2) I think Junior wants breakfast.
Choose one of the options and hit Enter
ask something with open response
; ;
will generate the following output:
Who is the one that knocks?
Answer Me!
Usage with promises
Promises can help cut down on code, and also allows you to use async/await.
When no callbacks are supplied, todd presumes you'll want a promise instead.
ask something with fixed answers (options)
; const answer = await ;
this will produce the following prompt:
Do you really want us coming back mrs. White?
1) Get out, leave us alone!
2) I think Junior wants breakfast.
Choose one of the options and hit Enter
if you choose an answer that Todd doesn't understand, Todd will repeat the question. The promise will only be resolved when the user answers with 1 of the expected answers
Do you really want us coming back mrs. White?
1) Get out, leave us alone!
2) I think Junior wants breakfast.
Choose one of the options and hit Enter
3
I didn't quite get that.
Do you really want us coming back mrs. White?
1) Get out, leave us alone!
2) I think Junior wants breakfast.
Choose one of the options and hit Enter
ask something with open response
; const answer = await ;
will generate the following output:
Who is the one that knocks?
Answer Me!