smartcli/dist/smartcli.classes.interaction.helpers.js

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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0Y2xpLmNsYXNzZXMuaW50ZXJhY3Rpb24uaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFBZ0IsQ0FBQyxDQUFBO0FBRXhCLFFBQU8sdUJBQXVCLENBQUMsQ0FBQTtBQUMvQixJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBRS9DOzs7OztHQUtHO0FBQ1EsaUJBQVMsR0FBRyxVQUFTLGNBQXFCLEVBQUUsRUFBRTtJQUNyRCxFQUFFLENBQUMsQ0FBQyxPQUFPLGNBQWMsSUFBSSxRQUFRLENBQUMsQ0FBQyxDQUFDO1FBQ3BDLE9BQU8sQ0FBQyxTQUFTLENBQUMsS0FBSyxDQUFDLHVCQUF1QixDQUFDLENBQUM7UUFDakQsTUFBTS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