61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
/// <reference path="./index.ts" />
|
|
module SmartcliInteraction {
|
|
export function init(){
|
|
|
|
smartcli.interaction = {};
|
|
/**
|
|
* 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}
|
|
*/
|
|
smartcli.interaction.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);
|
|
});
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @param questionString
|
|
* @param choiceOptions
|
|
* @param cb
|
|
* @returns {null}
|
|
*/
|
|
smartcli.interaction.getChoice = function(questionString:string, choiceOptions:string[], cb) {
|
|
if(!Array.isArray(choiceOptions)) {
|
|
return null;
|
|
}
|
|
|
|
//make inquirer compatible question object
|
|
var question = {
|
|
type: "list",
|
|
name: "userFeedback",
|
|
message: questionString,
|
|
choices: choiceOptions,
|
|
filter: function( val ) { return val.toLowerCase(); }
|
|
};
|
|
|
|
plugins.inquirer.prompt(question,function(answers){
|
|
var answer = answers.userFeedback;
|
|
cb(answer);
|
|
});
|
|
|
|
};
|
|
}
|
|
} |