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

Zhami/cli-interact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 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

Installation

npm install cli-interact

Usage

Queries

Presently, there are three queries:

getChar gets a single character from some set of allowed characters.

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