2016-03-14 06:12:00 +00:00
|
|
|
/// <reference path="typings/main.d.ts" />
|
2016-03-18 17:08:26 +00:00
|
|
|
/// <reference path="./smartcli.interfaces.ts" />
|
2015-11-08 23:58:40 +00:00
|
|
|
|
2016-03-18 17:08:26 +00:00
|
|
|
import plugins = require("./smartcli.plugins");
|
2015-11-08 23:58:40 +00:00
|
|
|
|
2016-03-18 17:08:26 +00:00
|
|
|
/**
|
|
|
|
* executes callback with answer to question as argument
|
|
|
|
* @param questionString the question you want to ask the user
|
|
|
|
* @param cb the function to execute with answer as param
|
|
|
|
* @returns {null}
|
|
|
|
*/
|
|
|
|
export let getAnswer = function(questionString:string, cb) {
|
|
|
|
if (typeof questionString != 'string') {
|
|
|
|
plugins.beautylog.error('no question specified');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
//make inquirer compatible question object
|
|
|
|
var question = {
|
|
|
|
type: "input",
|
|
|
|
name: "userFeedback",
|
|
|
|
message: questionString,
|
|
|
|
validate: function( value ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
plugins.inquirer.prompt([question],function(answers){
|
|
|
|
var answer = answers.userFeedback;
|
|
|
|
cb(answer);
|
|
|
|
});
|
|
|
|
};
|
2015-11-08 23:58:40 +00:00
|
|
|
|
2016-03-18 17:08:26 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param questionString
|
|
|
|
* @param choiceOptions
|
|
|
|
* @param cb
|
|
|
|
* @returns {null}
|
|
|
|
*/
|
|
|
|
export let getChoice = function(questionString:string, choiceOptions:string[], cb) {
|
|
|
|
if(!Array.isArray(choiceOptions)) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-11-08 23:58:40 +00:00
|
|
|
|
2016-03-18 17:08:26 +00:00
|
|
|
//make inquirer compatible question object
|
|
|
|
var question = {
|
|
|
|
type: "list",
|
|
|
|
name: "userFeedback",
|
|
|
|
message: questionString,
|
|
|
|
choices: choiceOptions,
|
|
|
|
filter: function( val ) { return val.toLowerCase(); }
|
|
|
|
};
|
2015-11-08 23:58:40 +00:00
|
|
|
|
2016-03-18 17:08:26 +00:00
|
|
|
plugins.inquirer.prompt(question,function(answers){
|
|
|
|
var answer = answers.userFeedback;
|
|
|
|
cb(answer);
|
|
|
|
});
|
2015-11-08 23:58:40 +00:00
|
|
|
|
2016-03-18 17:08:26 +00:00
|
|
|
};
|