cli-interact
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -14,5 +14,31 @@ //============================== | ||
answer = query('Give me a number'); | ||
answer = query('Case 1: You MAY give me a number: ', { | ||
allowNoAnswer : true | ||
}); | ||
if (answer !== '') { | ||
console.log('No answer.'); | ||
} else { | ||
console.log('Thank you for: ', answer); | ||
} | ||
console.log(); | ||
answer = query('Case 2: You MUST give me a number: '); | ||
console.log('you answered:', answer); | ||
console.log('the typeof of that is:', typeof answer) | ||
console.log('the typeof of that is:', typeof answer); | ||
console.log(); | ||
answer = query('Case 3: You MUST give me an integer: ', true); | ||
console.log('Thank you for: ', answer); | ||
console.log(); | ||
answer = query('Case 4: You MAY give me an answer. If you do, it MUST be an integer', { | ||
allowNoAnswer : true | ||
, requireInteger : true | ||
}); | ||
if (answer !== '') { | ||
console.log('No answer.'); | ||
} else { | ||
console.log('Thank you for: ', answer); | ||
} | ||
15
index.js
@@ -130,6 +130,17 @@ //============================== | ||
function getNumber (promptText, flagIntOnly) { | ||
function getNumber (promptText, opts) { | ||
var answer; | ||
var flagIntOnly; | ||
var flagAllowNoAnswer; | ||
var value; | ||
// for historical compatibility | ||
if (opts === true) { | ||
flagIntOnly = true; | ||
} else if (opts) { | ||
// better be an object; | ||
flagIntOnly = opts.requireInteger; | ||
flagAllowNoAnswer = opts.allowNoAnswer | ||
} | ||
while (true) { | ||
@@ -141,2 +152,4 @@ answer = readlineSync.question(promptText); | ||
process.exit(); | ||
} else if (flagAllowNoAnswer && (answer === '')) { | ||
break; | ||
} else { | ||
@@ -143,0 +156,0 @@ if (flagIntOnly) { |
{ | ||
"name": "cli-interact", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"title": "cli interact", | ||
@@ -5,0 +5,0 @@ "description": "Simple helper tools for interacting synchronously with user at command line", |
11405
307