@zowe/imperative
Version:
framework for building configurable CLIs
98 lines • 4.13 kB
JavaScript
;
/*
* 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.
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoInitCommandBuilder = void 0;
const error_1 = require("../../../../../../error");
const utilities_1 = require("../../../../../../utilities");
const messages_1 = require("../../../../../../messages");
const constants_1 = require("../../../../../../constants");
const AutoInitConstants_1 = require("../AutoInitConstants");
/**
* Class for generating auth-related commands
*/
class AutoInitCommandBuilder {
/**
* Construct the builder based on the auth config.
* @param mProfileType - the profile name of the profile type e.g. banana
* @param {Logger} mLogger - logger instance to use for the builder class
* @param {IImperativeAuthConfig} mAuthConfig - the config for the auth type
*/
constructor(mLogger, mAutoInitConfig, mProfileType) {
this.mLogger = mLogger;
this.mAutoInitConfig = mAutoInitConfig;
this.mProfileType = mProfileType;
this.mConfig = mAutoInitConfig;
if (this.mConfig == null) {
throw new error_1.ImperativeError({ msg: `Auto-init Builder Error: No auto-init config was supplied.` });
}
}
/**
* Build the command
* @return {ICommandDefinition}: The command definition.
*/
buildFull() {
return this.build();
}
/**
* Gets the "action" that this command builder is building.
* @return {string}: The auth action string
*/
getAction() {
return constants_1.Constants.AUTO_INIT_ACTION;
}
/**
* Build the command
* @return {ICommandDefinition}
*/
build() {
return this.buildAutoInitSegmentFromConfig();
}
/**
* Builds only the "auto-init" segment from the auto-init config.
* @return {ICommandDefinition}
*/
buildAutoInitSegmentFromConfig() {
var _a, _b, _c, _d;
const autoInitCommand = {
name: "auto-init",
type: "command",
summary: (_a = this.mConfig.autoInit) === null || _a === void 0 ? void 0 : _a.summary,
description: (_b = this.mConfig.autoInit) === null || _b === void 0 ? void 0 : _b.description,
handler: this.mConfig.handler,
options: [
AutoInitConstants_1.AutoInitConstants.AUTO_INIT_OPTION_USER_CONFIG,
AutoInitConstants_1.AutoInitConstants.AUTO_INIT_OPTION_GLOBAL_CONFIG,
AutoInitConstants_1.AutoInitConstants.AUTO_INIT_OPTION_DRY_RUN,
AutoInitConstants_1.AutoInitConstants.AUTO_INIT_OPTION_EDIT,
AutoInitConstants_1.AutoInitConstants.AUTO_INIT_OPTION_EDITOR,
AutoInitConstants_1.AutoInitConstants.AUTO_INIT_OPTION_OVERWRITE,
AutoInitConstants_1.AutoInitConstants.AUTO_INIT_OPTION_FOR_SURE,
...((_c = this.mConfig.autoInit) === null || _c === void 0 ? void 0 : _c.options) || []
],
examples: (_d = this.mConfig.autoInit) === null || _d === void 0 ? void 0 : _d.examples,
customize: {}
};
if (autoInitCommand.summary == null) {
autoInitCommand.summary = utilities_1.TextUtils.formatMessage(messages_1.autoInitCommandSummary.message, { source: this.mConfig.provider });
}
if (autoInitCommand.description == null) {
autoInitCommand.description = utilities_1.TextUtils.formatMessage(messages_1.autoInitCommandDesc.message, { source: this.mConfig.provider });
}
if (this.mProfileType != null) {
autoInitCommand.profile = {};
autoInitCommand.profile.optional = [this.mProfileType];
}
return autoInitCommand;
}
}
exports.AutoInitCommandBuilder = AutoInitCommandBuilder;
//# sourceMappingURL=AutoInitCommandBuilder.js.map