@zowe/imperative
Version:
framework for building configurable CLIs
111 lines • 5.41 kB
JavaScript
;
/*
* 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 logger_1 = require("../../../../../logger/");
const utilities_1 = require("../../../../../utilities");
const PluginIssues_1 = require("../../utilities/PluginIssues");
/**
* The install command handler for cli plugin install.
*
* @see {installDefinition}
*/
class ListHandler {
constructor() {
/**
* A logger for this class
*
* @private
* @type {Logger}
*/
this.log = logger_1.Logger.getImperativeLogger();
}
/**
* Process the command and input.
*
* @param {IHandlerParameters} params Parameters supplied by yargs
*
* @returns {Promise<ICommandResponse>} The command response
*
* @throws {ImperativeError}
*/
process(params) {
return __awaiter(this, void 0, void 0, function* () {
const chalk = utilities_1.TextUtils.chalk;
const installedPlugins = PluginIssues_1.PluginIssues.instance.getInstalledPlugins();
params.response.data.setObj(installedPlugins);
let listOutput = "";
let firstTime = true;
// Boolean to check if any of the plug-ins installed originate from Zowe Cli V2
let containsLegacyPlugin = false;
for (const pluginName of Object.keys(installedPlugins).sort((a, b) => a.localeCompare(b))) {
if (Object.prototype.hasOwnProperty.call(installedPlugins, pluginName)) {
// Build the console output
if (!params.arguments.short) {
if (firstTime) {
listOutput = `\n${chalk.yellow.bold("Installed plugins:")} \n\n`;
}
listOutput = listOutput + `${chalk.yellow.bold(" -- pluginName: ")}` +
`${chalk.red.bold(pluginName)} \n`;
listOutput = listOutput + `${chalk.yellow.bold(" -- package: ")}` +
`${chalk.red.bold(installedPlugins[pluginName].package)} \n`;
listOutput = listOutput + `${chalk.yellow.bold(" -- version: ")}` +
`${chalk.red.bold(installedPlugins[pluginName].version)} \n`;
if (installedPlugins[pluginName].registry) {
containsLegacyPlugin = true;
listOutput = listOutput + `${chalk.yellow.bold(" -- registry: ")}` +
`${chalk.red.bold(installedPlugins[pluginName].registry)}` +
`${chalk.yellow.bold(" (?)")}` + "\n\n";
}
else {
listOutput = listOutput + `${chalk.yellow.bold(" -- location: ")}` +
`${chalk.red.bold(installedPlugins[pluginName].location)}` + "\n\n";
}
}
else {
listOutput += `${chalk.yellow(pluginName)}@${installedPlugins[pluginName].version}\n`;
}
// Write to the log file
if (firstTime) {
this.log.simple(" ");
this.log.simple("Installed plugins:");
this.log.simple(" ");
firstTime = false;
}
this.log.simple(" pluginName: " + pluginName);
this.log.simple(" package: " + installedPlugins[pluginName].package);
this.log.simple(" version: " + installedPlugins[pluginName].version);
this.log.simple(" registry: " + installedPlugins[pluginName].location);
this.log.simple(" ");
}
}
if (containsLegacyPlugin) {
listOutput += chalk.yellow.bold("Plug-ins marked with (?) may be invalid or out of date, and might need to be reinstalled.") + "\n";
}
if (listOutput === "") {
listOutput = "No plugins have been installed into your CLI application.";
}
// Write to the results of the list command to console
params.response.console.log(listOutput);
});
}
}
exports.default = ListHandler;
//# sourceMappingURL=list.handler.js.map