@broadcom/endevor-bridge-for-git-for-zowe-cli
Version:
Endevor Bridge for Git plug-in for Zowe CLI
68 lines • 3.01 kB
JavaScript
;
/*
* 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.OptionValidator = void 0;
const imperative_1 = require("@zowe/imperative");
const object_1 = require("../../utils/object");
class OptionValidator {
constructor() {
this.missingOptions = new Map();
}
/**
* Adds the option as a missing option
*
* @param optionDefinition missing option
*/
addMissingOption(optionDefinition) {
const groupId = (0, object_1.isNil)(optionDefinition.group) ? OptionValidator.DEFAULT_OPTIONS_GROUP : optionDefinition.group;
if (this.missingOptions.has(groupId)) {
this.missingOptions.get(groupId).push(optionDefinition.name);
}
else {
this.missingOptions.set(groupId, [optionDefinition.name]);
}
}
/**
* Checks that there is not missing required options. It must be checked at the beginning of the command handlers.
*/
validateRequiredOptions() {
if (this.missingOptions.size > 0) {
let msg = OptionValidator.MISSING_ARGS_MSG.concat("\n");
const sortedMap = new Map([...this.missingOptions.entries()].sort());
sortedMap.forEach((options, group) => msg = msg.concat("- ").concat(group).concat(": ").concat(options.join(", ").concat("\n")));
throw new imperative_1.ImperativeError({ msg });
}
}
isMissingOptions(group) {
return this.missingOptions.has(group);
}
isMissingCredentials(session) {
return ((0, object_1.isNil)(session.tokenValue) || (0, object_1.isNil)(session.tokenType)) &&
((0, object_1.isNil)(session.user) || (0, object_1.isNil)(session.password));
}
}
exports.OptionValidator = OptionValidator;
OptionValidator.MISSING_ARGS_MSG = "missing arguments ";
OptionValidator.DEFAULT_OPTIONS_GROUP = "Options";
//# sourceMappingURL=OptionValidator.js.map