cli-interact
Advanced tools
Comparing version 0.1.1 to 0.1.2
50
index.js
@@ -31,2 +31,23 @@ //============================== | ||
function getInteger (promptText) { | ||
var answer; | ||
var value; | ||
promptText += ': '; | ||
while (true) { | ||
answer = readlineSync.question(promptText); | ||
if (answer === "\u0003") { | ||
// Ctl-C | ||
process.exit(); | ||
} else { | ||
value = parseInt(answer, 10); | ||
if (value.toString() === answer) { | ||
break; | ||
} | ||
} | ||
} | ||
return value; | ||
} | ||
function getIPversion () { | ||
@@ -36,2 +57,30 @@ return getChar('IP Version', '46'); | ||
function getNumber (promptText, flagIntOnly) { | ||
var answer; | ||
var value; | ||
promptText += ': '; | ||
while (true) { | ||
answer = readlineSync.question(promptText); | ||
if (answer === "\u0003") { | ||
// Ctl-C | ||
process.exit(); | ||
} else { | ||
if (flagIntOnly) { | ||
value = parseInt(answer, 10); | ||
if (value.toString() === answer) { | ||
break; | ||
} | ||
} else { | ||
value = parseFloat(answer); | ||
if (!isNaN(value) && isFinite(answer)) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
return value; | ||
} | ||
function getYesNo (title, flagAllowNoAnswer) { | ||
@@ -73,2 +122,3 @@ var answer; | ||
, getIPversion : getIPversion | ||
, getNumber : getNumber | ||
, getYesNo : getYesNo | ||
@@ -75,0 +125,0 @@ , question : question |
{ | ||
"name": "cli-interact", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"title": "cli interact", | ||
@@ -5,0 +5,0 @@ "description": "Simple helper tools for interacting synchronously with user at command line", |
8162
12
191