56 lines
5.3 KiB
JavaScript
56 lines
5.3 KiB
JavaScript
"use strict";
|
|
require("typings-global");
|
|
require("./smartcli.interfaces");
|
|
var plugins = require("./smartcli.plugins");
|
|
/**
|
|
* 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}
|
|
*/
|
|
exports.getAnswer = function (questionString, 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}
|
|
*/
|
|
exports.getChoice = function (questionString, choiceOptions, 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);
|
|
});
|
|
};
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmludGVyYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFFeEIsUUFBTyx1QkFBdUIsQ0FBQyxDQUFBO0FBQy9CLElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFFL0M7Ozs7O0dBS0c7QUFDUSxpQkFBUyxHQUFHLFV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