node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org »

prompt-promise

npm mit license build status coverage status deps status

Sane CLI user-input (command prompt, confirm, multiline, password) as promises, it can be used with co@4

Install

npm i --save prompt-promise

Run examples

npm run with-co
npm run without-co

Usage

For more use-cases see examples

var co = require('co');
var prompt = require('prompt-promise');
var res = [];
 
prompt('username: ')
.then(function username(val) {
  res.push(val);
  return prompt.password('password: ');
})
.then(function pasword(val) {
  res.push(val);
  console.log(res);
  prompt.done();
})
.catch(function rejected(err) {
  console.log('error:', err.stack);
  prompt.finish();
});
 
// or with `co@4` 
co(function * genPrompt() {
  var username = yield prompt('username: ');
  var password = yield prompt.password('password: ');
 
  return yield [username, password];
})
.then(function fulfilled(array) {
  console.log('response:', array);
  prompt.end();
})
.catch(function rejected(err) {
  console.log('error:', err.stack);
  process.stdin.pause();
});

.end(), .done(), .finish() are just aliases for process.stdin.pause(); its required, nah..

Author

Charlike Mike Reagent

License MIT license

Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
Copyright (c) 2014 TJ Holowaychuk, contributors.
Released under the MIT license.


Powered and automated by kdf, January 31, 2015