add read util

This commit is contained in:
Joao Moreno 2015-09-18 20:06:13 +02:00
parent 854e73e592
commit 62a77d567f

View file

@ -1,4 +1,6 @@
import { Promise } from 'q';
import { Promise, nfcall } from 'q';
import { assign } from 'lodash';
import _read = require('read');
export function fatal(message: any, ...args: any[]) {
if (message instanceof Error && /^cancell?ed$/i.test(message.message)) {
@ -7,4 +9,9 @@ export function fatal(message: any, ...args: any[]) {
console.error('Error:', message, ...args);
process.exit(1);
}
export function read(prompt: string, options: _read.Options = {}): Promise<string> {
return nfcall<string>(_read, assign({ prompt }, options))
.spread(r => r);
}