UNPKG

@zowe/imperative

Version:
125 lines 6.36 kB
"use strict"; /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("../../../../../config"); const npm_interface_1 = require("../../../plugins/utilities/npm-interface"); const utilities_1 = require("../../../../../utilities"); /** * Handler for the convert profiles command. */ class ConvertProfilesHandler { /** * Process the command input and display output. * * @param {IHandlerParameters} params Parameters supplied by yargs * * @throws {ImperativeError} */ process(params) { return __awaiter(this, void 0, void 0, function* () { var _a; const convertOpts = { deleteV1Profs: false }; if ((_a = params.arguments) === null || _a === void 0 ? void 0 : _a.delete) { convertOpts.deleteV1Profs = true; if (params.arguments.prompt == null || params.arguments.prompt === true) { params.response.console.log("If you confirm the deletion of V1 profiles, they are deleted from disk after\n" + "a successful conversion. Otherwise, they remain but are no longer used.\n" + "You can also delete your V1 profiles later.\n"); const answer = yield params.response.console.prompt("Do you want to delete your V1 profiles now [y/N]: "); if (answer.charAt(0).toLowerCase() !== "y") { convertOpts.deleteV1Profs = false; } } } const convertResult = yield config_1.ConvertV1Profiles.convert(convertOpts); /* Uninstall the V1 SCS plugin. * * The uninstall cannot be done in ConvertV1Profiles.convert because circular * dependencies cause problems in other unrelated modules that import from * "@zowe/imperative". * * Add our messages to those already in the response object so that we can * display all messages together later. */ if (convertResult.v1ScsPluginName) { try { (0, npm_interface_1.uninstall)(convertResult.v1ScsPluginName); const newMsg = new config_1.ConvertMsg(config_1.ConvertMsgFmt.REPORT_LINE | config_1.ConvertMsgFmt.PARAGRAPH, `Successfully uninstalled plug-in ${convertResult.v1ScsPluginName}.`); convertResult.msgs.push(newMsg); } catch (error) { let newMsg = new config_1.ConvertMsg(config_1.ConvertMsgFmt.ERROR_LINE | config_1.ConvertMsgFmt.PARAGRAPH, `Failed to uninstall plug-in ${convertResult.v1ScsPluginName}.`); convertResult.msgs.push(newMsg); newMsg = new config_1.ConvertMsg(config_1.ConvertMsgFmt.ERROR_LINE | config_1.ConvertMsgFmt.INDENT, error.message); convertResult.msgs.push(newMsg); } } // show all report messages followed by error messages this.showMsgsByType(convertResult.msgs, config_1.ConvertMsgFmt.REPORT_LINE, params.response.console); this.showMsgsByType(convertResult.msgs, config_1.ConvertMsgFmt.ERROR_LINE, params.response.console); }); } /** * Show all of the messages of a given type. * The intent is to allow our caller to show a report of all actions, * followed by a report of all errors. * * @param setOfMsgs The available set of messages to display. * @param msgTypeToShow The type of message to display. * Either ConvertMsgFmt.REPORT_LINE or ConvertMsgFmt.ERROR_LINE. * @param consoleApiFun The IHandlerResponseConsoleApi object used to display * messages in a CLI terminal. */ showMsgsByType(setOfMsgs, msgTypeToShow, consoleApiFun) { let firstMsgLine = true; for (const nextMsg of setOfMsgs) { let startingMsgText = ""; if (nextMsg.msgFormat & msgTypeToShow) { if (firstMsgLine) { firstMsgLine = false; if (msgTypeToShow & config_1.ConvertMsgFmt.ERROR_LINE) { startingMsgText = "\nThe following operation(s) were not completed:\n"; } // We want one newline before our first message, but avoid a double newline if (!(nextMsg.msgFormat & config_1.ConvertMsgFmt.PARAGRAPH)) { startingMsgText += "\n"; } } if (nextMsg.msgFormat & config_1.ConvertMsgFmt.PARAGRAPH) { startingMsgText += "\n"; } if (nextMsg.msgFormat & config_1.ConvertMsgFmt.INDENT) { startingMsgText += " "; } if (msgTypeToShow & config_1.ConvertMsgFmt.REPORT_LINE) { consoleApiFun.log(startingMsgText + nextMsg.msgText); } else { consoleApiFun.error(utilities_1.TextUtils.chalk.red(startingMsgText + nextMsg.msgText)); } } } } } exports.default = ConvertProfilesHandler; //# sourceMappingURL=convert-profiles.handler.js.map