UNPKG

@broadcom/endevor-bridge-for-git-for-zowe-cli

Version:

Endevor Bridge for Git plug-in for Zowe CLI

94 lines 4.32 kB
"use strict"; /* * Copyright (c) 2019 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.OptionUtils = void 0; const object_1 = require("../../utils/object"); const _ = require("lodash"); class OptionUtils { /** * It is used to add the default value to the description of the option * * @param defaultValue value */ static defaultValueDescription(defaultValue) { return `\n\nDefault value: ${defaultValue}`; } constructor(optionValidator) { this.optionValidator = optionValidator; } /** * Returns the value of a required option. Precedence: arguments, profile * * @param isRequired if true, the option is added to missing options if not found * @param optionDefinition definition of the specific option * @param args list of arguments that contains the option * @param profile? profile that contains the option * @param baseProfile? base profile that contains the option * @param defaultValue default value if not found */ getOption(isRequired, optionDefinition, args, profile, baseProfile, defaultValue) { let optionValue = args[_.camelCase(optionDefinition.name)]; // if there is no argument value and there is service profile get it from there if ((0, object_1.isNil)(optionValue) && (0, object_1.isNotNil)(profile)) { // profile value has priority if only if the argument value is undefined optionValue = profile[this.getProfileFieldName(optionDefinition)]; } // if there is no argument value and the option is not found in the service profile , get it from base profile if ((0, object_1.isNil)(optionValue) && (0, object_1.isNotNil)(baseProfile)) { optionValue = baseProfile[this.getProfileFieldName(optionDefinition)]; } // otherwise get the default value if ((0, object_1.isNil)(optionValue) && (0, object_1.isNotNil)(defaultValue)) { optionValue = defaultValue; } if (isRequired && (0, object_1.isNil)(optionValue)) { this.optionValidator.addMissingOption(optionDefinition); } return optionValue; } /** * Returns the value of an option passed as an argument in the command. If it's not specified it returns undefined. */ getOptionFromArgument(optionDefinition, args) { return args[_.camelCase(optionDefinition.name)]; } /** * Returns the prefix of the options. It is used when using external profiles (e.g. Endevor, z/OSMF) */ getOptionPrefix() { // By default the options do not have prefix return ""; } /** * Returns the key of the profile field in camel case. The options created from profiles must always contain the original field name. * E.g: 'my-field' in the profile 'my-profile' must be translated to 'my-profile-my-field' so that the field name is 'myField' * * @param optionDefinition definition of the specific option */ getProfileFieldName(optionDefinition) { return _.camelCase(optionDefinition.name.replace(this.getOptionPrefix(), "")); } } exports.OptionUtils = OptionUtils; //# sourceMappingURL=OptionUtils.js.map