@zowe/imperative
Version:
framework for building configurable CLIs
84 lines • 3.87 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 EnvItems_1 = require("./EnvItems");
const EnvQuery_1 = require("./EnvQuery");
const TextUtils_1 = require("../../../../../utilities/src/TextUtils");
/**
* Handler to report a user's wroking environment.
*
* We detect and report information from the user environment, including
* installed 3rd party prerrequisites. We report those findings.
*
* We also maintain a set of known problem conditions (like broken NPM
* versions which happen way too often). We use that data to report the
* probelem to the customer and any known workaround.
*
* @export
*/
class ReportEnvHandler {
process(cmdParams) {
return __awaiter(this, void 0, void 0, function* () {
yield this.displayEnvReport(cmdParams.response);
cmdParams.response.data.setExitCode(0);
});
}
// __________________________________________________________________________
/**
* Display a report of all items of interest and any problems detected.
*
* @param consoleApi Console response object to which we will write messages.
*/
displayEnvReport(responseApi) {
return __awaiter(this, void 0, void 0, function* () {
const { EOL } = require("os");
for (const nextItemId of Object.keys(EnvItems_1.ItemId).map(keyVal => parseInt(keyVal)).filter(keyVal => !isNaN(keyVal))) {
// These items have a progress bar. Output a newline beforehand.
if (nextItemId == EnvItems_1.ItemId.NPM_VER || nextItemId == EnvItems_1.ItemId.ZOWE_CONFIG_INFO) {
responseApi.console.error(EOL);
}
yield this.displayEnvItem(nextItemId, responseApi);
}
responseApi.console.log(`This information contains site-specific data. Redact anything required${EOL}` +
"by your organization before sending this information to outside companies.");
});
}
// __________________________________________________________________________
/**
* Display a specific item and any problems detected.
*
* @param consoleApi Console response object to which we will write messages.
*/
displayEnvItem(itemId, responseApi) {
return __awaiter(this, void 0, void 0, function* () {
const getItemOpts = {
progressApi: responseApi.progress
};
const getResult = yield EnvQuery_1.EnvQuery.getEnvItemVal(itemId, getItemOpts);
responseApi.console.log(getResult.itemValMsg);
if (getResult.itemProbMsg.length > 0) {
responseApi.console.log(TextUtils_1.TextUtils.chalk.red(" " + getResult.itemProbMsg));
}
});
}
}
exports.default = ReportEnvHandler;
//# sourceMappingURL=Report-env.handler.js.map
;