Skip to content

Simple helper tools for interacting synchronously with user at command line.

License

Notifications You must be signed in to change notification settings

damonridenow/cli-interact

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cli-interact

Simple helper tools for interacting synchronously with user at command line. The interface is used with process.stdin and process.stdout in order to accept user input.

Example

var	query = require('cli-interact').getYesNo;
var answer = query('Is it true');
console.log('you answered:', answer);
$ node examples/getYesNoNone.js
Is it true (y/n)? j
Is it true (y/n)? y
you answered: true

Example using getChar and new syntax

var choices = ['All','None','First','Last'];
var query = require('cli-interact').getChar;
var answer;

answer = query('Tell me one of '+choices.toString(), choices.toString());
console.log('you answered:', answer);

Installation

npm install cli-interact

Usage

Queries

Presently, there are three queries:

getChar gets a single character from some set of allowed characters. (now it takes more than one character)

getIPversion gets a single character, either '4' or '6'.

getYesNo prompts for 'y' or 'n', returns true/false. Can be configured to allow no response (returns undefined).

And a passthorugh question to access the underlying readlineSync.question method.

Notes

Uses the readline-sync module. See it for more information.

Platforms

The your Node and OS may not support interactively reading from stdin. The stdin interfaces are different by platforms. If in those platforms, an error is thrown by readlineSync.

try {
  answer = readlineSync.question('What is your favorite food? :');
} catch (e) {
  console.error(e);
  process.exit(1);
}

Release History

  • 2014-11-14 v0.1.0 Initial release.

About

Simple helper tools for interacting synchronously with user at command line.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%