UNPKG

@zowe/imperative

Version:
74 lines 4.11 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 Imperative_1 = require("../../../imperative/src/Imperative"); const CommandUtils_1 = require("../../../cmd/src/utils/CommandUtils"); const utilities_1 = require("../../../utilities"); const WebHelpManager_1 = require("../../../cmd/src/help/WebHelpManager"); /** * The default command handler for the top level/root command * Allows the user to check the version of the package. * If they haven't specified --version, the help prints */ class DefaultRootCommandHandler { process(params) { return __awaiter(this, void 0, void 0, function* () { // if --version is specified if (params.arguments.version) { // load the user's package.json to check the version of their package const packageJson = utilities_1.ImperativeConfig.instance.callerPackageJson; const jsonResponse = { version: packageJson.version }; params.response.console.log("CLI Version: " + packageJson.version); if (packageJson.zoweVersion) { params.response.console.log("Zowe Release Version: " + packageJson.zoweVersion); jsonResponse.zoweVersion = packageJson.zoweVersion; } params.response.data.setObj(jsonResponse); params.response.data.setMessage("Version(s) displayed"); } else if (params.arguments.availableCommands) { // Gather and display the full set of commands available to the CLI with descriptions const cmdList = CommandUtils_1.CommandUtils.flattenCommandTree(Imperative_1.Imperative.fullCommandTree); cmdList.forEach((cmd) => { if (cmd.command.type === "command") { params.response.console.log(Imperative_1.Imperative.highlightWithPrimaryColor(`${Imperative_1.Imperative.rootCommandName.trim()} ${cmd.fullName.trim()}`)); params.response.console.log(""); params.response.console.log(utilities_1.TextUtils.wordWrap(cmd.command.description, utilities_1.TextUtils.DEFAULT_WRAP_WIDTH, "\t")); params.response.console.log(""); } }); params.response.data.setObj(Imperative_1.Imperative.fullCommandTree, false); } else if (params.arguments.helpWeb) { WebHelpManager_1.WebHelpManager.instance.openRootHelp(params.response); } else { params.response.console.log(Buffer.from(Imperative_1.Imperative.getHelpGenerator({ commandDefinition: params.definition, fullCommandTree: params.fullDefinition, experimentalCommandsDescription: utilities_1.ImperativeConfig.instance.loadedConfig.experimentalCommandDescription }).buildHelp())); } }); } } exports.default = DefaultRootCommandHandler; //# sourceMappingURL=DefaultRootCommandHandler.js.map