@broadcom/jclcheck-for-zowe-cli
Version:
JCLCheck Plug-in for Zowe CLI
134 lines (133 loc) • 7.24 kB
JavaScript
;
/**
* Copyright (c) 2025. Broadcom. All rights reserved. The term
* "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This software and all information contained therein is
* confidential and proprietary and shall not be duplicated,
* used, disclosed, or disseminated in any way except as
* authorized by the applicable license agreement, without the
* express written permission of Broadcom. All authorized
* reproductions must be marked with this language.
* EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO
* THE EXTENT PERMITTED BY APPLICABLE LAW, BROADCOM PROVIDES THIS
* SOFTWARE WITHOUT WARRANTY OF ANY KIND, INCLUDING WITHOUT
* LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL BROADCOM
* BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY LOSS OR
* DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
* INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS
* INTERRUPTION, GOODWILL, OR LOST DATA, EVEN IF BROADCOM IS
* EXPRESSLY ADVISED OF SUCH LOSS OR DAMAGE.
*
**/
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 imperative_1 = require("@zowe/imperative");
const ResponseParser_1 = require("../../util/ResponseParser");
const JCLCheckSessionUtils_1 = require("../JCLCheckSessionUtils");
/**
* The base handler class for the "check" action. The sub-commands under "check" are
* variations of the same action, just with different data sources. This is the
* common handler for each.
* @export
* @class LocalFile
* @implements {ICommandHandler}
*/
class BaseCheckHandler {
/**
* Base command handler for "check" command.
* @param params The input handler parameters from Imperative (arguments, profiles, etc.)
*/
process(params) {
return __awaiter(this, void 0, void 0, function* () {
// Set fields for handlers
this.args = params.arguments;
this.resp = params.response;
// Create a session config object for the JCLCHECK API
const sessCfg = JCLCheckSessionUtils_1.JCLCheckSessionUtils.createJCLCheckSessCfgFromArgs(params.arguments);
// Handle tokens and any missing connection properties
const connectableSessCfg = yield imperative_1.ConnectionPropsForSessCfg.addPropsOrPrompt(sessCfg, params.arguments);
this.session = new imperative_1.Session(connectableSessCfg);
// Base handler control opts
const options = params.arguments.jclcheckOptions;
const rawOutput = params.arguments.rawOutput;
const maxReturnCode = params.arguments.maxReturnCode;
// Invoke the implementation and set the data object response
const jclResponse = yield this.performCheck(options);
params.response.data.setObj(jclResponse);
// If the raw output option was not specified and the parsing failed
// Then fail the command with the parsing errors
if ((this.args.rawOutput == null || this.args.rawOutput === false)
&& !jclResponse.data.parsedAvailable) {
const err = { msg: `JCLCheck failed to parse report. Reissue the command with "--raw-output" to see report contents.` };
if (jclResponse.messages != null) {
err.additionalDetails = "";
jclResponse.messages.forEach((message) => {
const msg = ResponseParser_1.ResponseParser.formatMessage(message, true);
const tbl = imperative_1.TextUtils.getTable(msg, "yellow", BaseCheckHandler.MaxTableColumnWidth, false, false, false);
err.additionalDetails += tbl;
});
}
// Throw the error for display
throw new imperative_1.ImperativeError(err);
}
// If requested, print the raw report output
if (rawOutput) {
// If the response is null only print the return code
if (jclResponse.data.raw != null) {
params.response.console.log(jclResponse.data.raw);
}
// Fail the command if the return code is higher than the max rc
this.evalMaxRc(maxReturnCode, jclResponse.data.jclCheckCode);
}
else {
params.response.console.log(`JCLCHECK Return Code: "${jclResponse.data.jclCheckCode}"`);
// If the parsed reports are available, output just the error messages table
if (jclResponse.data.parsedReports != null &&
jclResponse.data.parsedReports.jobReports != null) {
for (const jobReports of jclResponse.data.parsedReports.jobReports) {
if (jobReports.reports.report6 != null) {
params.response.console.log(`\n'${jobReports.reports.report6.flaggedStatements}` +
`' statement(s) flagged for job '${jobReports.reports.report6.jobname}' ` +
`with a maximum severity of '${jobReports.reports.report6.maximumSeverity}'\n`);
}
const table = ResponseParser_1.ResponseParser.buildJobReportOutput(jobReports);
if (table.length > 0) {
params.response.format.output({
output: table,
format: "table",
header: true,
fields: ["Stmnt", "Sev", "ID", "Msg"]
});
}
}
// Fail the command if the return code is higher than the max rc
this.evalMaxRc(maxReturnCode, jclResponse.data.jclCheckCode);
}
}
});
}
/**
* Evaluate the max RC parameter and throw an error if exceeded.
* @param maxRc The maximum acceptable return code.
* @param jclcheckRc The actual return code.
*/
evalMaxRc(maxRc, jclcheckRc) {
if (maxRc != null && jclcheckRc > maxRc) {
this.resp.console.log("");
throw new imperative_1.ImperativeError({ msg: `JCLCHECK Return Code exceeded max return code: ${maxRc}` });
}
}
}
BaseCheckHandler.MaxTableColumnWidth = 100;
exports.default = BaseCheckHandler;
//# sourceMappingURL=BaseCheck.handler.js.map