liveperson-functions-cli
Version:
LivePerson Functions CLI
57 lines • 2.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PullController = void 0;
const errorCodes_1 = require("../shared/errorCodes");
const pull_view_1 = require("../view/pull.view");
const faasFactory_service_1 = require("../service/faasFactory.service");
const file_service_1 = require("../service/file.service");
class PullController {
constructor(
/* istanbul ignore next */ { pullView = new pull_view_1.PullView(), fileService = new file_service_1.FileService(), } = {}) {
this.pullView = pullView;
this.fileService = fileService;
}
/**
* Pulls the passed functions from the platform
* @param {IPullConfig} { lambdaFunctions, inputFlags } - passed functions and flags
* @returns {Promise<void>} - pull view
* @memberof PullController
*/
async pull({ lambdaFunctions, inputFlags, }) {
try {
const faasService = await faasFactory_service_1.factory.get();
if (lambdaFunctions.length === 0 && !(inputFlags === null || inputFlags === void 0 ? void 0 : inputFlags.all)) {
lambdaFunctions = [this.fileService.getFunctionFolderName()];
}
const lambdasToPull = (inputFlags === null || inputFlags === void 0 ? void 0 : inputFlags.all)
? await faasService.getAllLambdas()
: (await faasService.getLambdasByNames(lambdaFunctions));
let confirmedLambdasToPull = [];
if (inputFlags === null || inputFlags === void 0 ? void 0 : inputFlags.yes) {
confirmedLambdasToPull = lambdasToPull;
}
else {
const answer = await this.pullView.askForConfirmation(lambdasToPull, faasService.accountId);
confirmedLambdasToPull = lambdasToPull.filter((entry) => answer[entry.name]);
/* istanbul ignore else */
if (confirmedLambdasToPull.length === 0) {
return;
}
}
await this.pullView.showPullProcess({
confirmedLambdasToPull,
noWatch: inputFlags === null || inputFlags === void 0 ? void 0 : inputFlags['no-watch'],
});
}
catch (error) {
const prettyError = {
message: error.message || error.errorMsg,
ref: 'https://github.com/LivePersonInc/faas-cli#pull',
code: errorCodes_1.CLIErrorCodes.FailedToPull,
};
this.pullView.showErrorMessage(prettyError);
}
}
}
exports.PullController = PullController;
//# sourceMappingURL=pull.controller.js.map