import * as merge from 'lodash/merge'; import * as inquirer from 'inquirer'; export function out( text: string, nl: boolean = true ) { process.stdout.write(text) if ( nl ) process.stdout.write('\n') } export function dump( ...args: any[] ) { args.forEach(( arg ) => console.dir(arg, { colors : true, depth : 5, showHidden : true })) } export class Questions { static askChoice( question: string, choices: any[], opts: any = {}, cb?: any ) { opts = merge({ type : 'list', message : question, choices : choices }, opts); return Questions.ask(opts, cb); } static askInput( question: string, opts: any = {}, cb?: any ) { opts = merge({ type : 'input', message : question }, opts); return Questions.ask(opts, cb); } static askPassword( question: string, opts: any = {}, cb?: any ) { opts = merge({ type : 'password', message : question }, opts); return Questions.ask(opts, cb); } static ask( opts: any, cb?: any ) { if ( !opts.name ) { opts.name = 'ask' } return ( inquirer.prompt(opts)).then(( answers: any ) => { //inspect('answers', answers, 'cb', cb, 'answer', answers[opts.name]); if ( cb ) cb(answers[opts.name]); }) } }