UNPKG

@zowe/imperative

Version:
76 lines 3.61 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 JSONC = require("comment-json"); const config_1 = require("../../../../../config"); const ConfigUtils_1 = require("../../../../../config/src/ConfigUtils"); const error_1 = require("../../../../../error"); const utilities_1 = require("../../../../../utilities"); class SetHandler { /** * Process the command and input. * * @param {IHandlerParameters} params Parameters supplied by yargs * * @throws {ImperativeError} */ process(params) { return __awaiter(this, void 0, void 0, function* () { // Create the config, load the secure values, and activate the desired layer const config = utilities_1.ImperativeConfig.instance.config; config.api.layers.activate(params.arguments.userConfig, params.arguments.globalConfig); // Store the value securely if --secure was passed or the property name is in secure array let secure = params.arguments.secure; if (secure == null) { secure = config.api.secure.secureFields().includes(params.arguments.property); } // Setup the credential vault API for the config if (secure && config.api.secure.loadFailed) { throw ConfigUtils_1.ConfigUtils.secureSaveError(); } // Get the value to set let value; if (params.arguments.value) { value = params.arguments.value; } else { value = yield params.response.console.prompt(`Please enter the value for ${params.arguments.property}: `, { hideText: secure }); } if (params.arguments.json) { try { // Typecasting because of this issue: https://github.com/kaelzhang/node-comment-json/issues/42 value = JSONC.parse(value, null, true); } catch (e) { throw new error_1.ImperativeError({ msg: `could not parse JSON value: ${e.message}` }); } } else { value = ConfigUtils_1.ConfigUtils.coercePropValue(value, config_1.ConfigSchema.findPropertyType(params.arguments.property, config.properties)); } // Set the value in the config, save the secure values, write the config layer config.set(params.arguments.property, value, { secure }); yield config.save(); }); } } exports.default = SetHandler; //# sourceMappingURL=set.handler.js.map