This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
CompleteProfilesGroupBuilder.ts
137 lines (122 loc) · 5.7 KB
/
CompleteProfilesGroupBuilder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* 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.
*
*/
import { ICommandDefinition, ICommandProfileTypeConfiguration } from "../../../../cmd";
import {
createProfilesCommandDesc, createProfilesCommandSummary,
deleteProfilesCommandDesc, deleteProfilesCommandSummary,
listProfileCommandDesc, listProfileCommandSummary,
setProfileActionDesc, setProfileActionSummary,
updateProfileCommandDesc, updateProfileCommandSummary,
validateProfileGroupDesc, validateProfileCommandSummary
} from "../../../../messages";
import { Constants } from "../../../../constants";
import { ProfilesCreateCommandBuilder } from "./ProfilesCreateCommandBuilder";
import { ProfilesUpdateCommandBuilder } from "./ProfilesUpdateCommandBuilder";
import { ProfilesDeleteCommandBuilder } from "./ProfilesDeleteCommandBuilder";
import { ProfilesValidateCommandBuilder } from "./ProfilesValidateCommandBuilder";
import { ProfilesListCommandBuilder } from "./ProfilesListCommandBuilder";
import { ProfilesSetCommandBuilder } from "./ProfilesSetCommandBuilder";
import { Logger } from "../../../../logger/index";
import { isNullOrUndefined } from "util";
import { IProfileTypeConfiguration } from "../../../../profiles";
/**
* Generate a complete group of commands for maintaining configuration profiles
* based on provided profile definitions.
*/
export class CompleteProfilesGroupBuilder {
/**
* Get the complete profile group of commands
* @param {ICommandProfileTypeConfiguration[]} profiles - the profile configurations to convert to commands
* @param {Logger} logger - logger to use in the builder classes
* @returns {ICommandDefinition} - the complete profile group of commands
*/
public static getProfileGroup(profiles: IProfileTypeConfiguration[], logger: Logger): ICommandDefinition {
const profileGroup: ICommandDefinition = {
name: Constants.PROFILE_GROUP,
description: "Create and manage configuration profiles",
type: "group",
children: []
};
const createGroup: ICommandDefinition = {
name: Constants.CREATE_ACTION,
description: createProfilesCommandDesc.message,
summary: createProfilesCommandSummary.message,
aliases: ["cre"],
type: "group",
children: [],
};
const deleteGroup: ICommandDefinition = {
name: Constants.DELETE_ACTION,
description: deleteProfilesCommandDesc.message,
summary: deleteProfilesCommandSummary.message,
aliases: ["rm"],
type: "group",
children: [],
};
const setGroup: ICommandDefinition = {
name: Constants.SET_ACTION,
summary: setProfileActionSummary.message,
description: setProfileActionDesc.message,
type: "group",
aliases: ["set"],
children: [],
};
const updateGroup: ICommandDefinition = {
name: Constants.UPDATE_ACTION,
description: updateProfileCommandDesc.message,
summary: updateProfileCommandSummary.message,
aliases: ["upd"],
type: "group",
children: [],
};
const validateGroup: ICommandDefinition = {
name: Constants.VALIDATE_ACTION,
description: validateProfileGroupDesc.message,
summary: validateProfileCommandSummary.message,
aliases: ["val"],
type: "group",
children: [],
};
const listGroup: ICommandDefinition = {
name: Constants.LIST_ACTION,
description: listProfileCommandDesc.message,
summary: listProfileCommandSummary.message,
aliases: ["ls"],
type: "group",
children: [],
};
const cmdGroups: ICommandDefinition[] = [];
for (const profile of profiles) {
const createCommandAction = new ProfilesCreateCommandBuilder(profile.type, logger, profile);
const updateCommandAction = new ProfilesUpdateCommandBuilder(profile.type, logger, profile);
const deleteCommandAction = new ProfilesDeleteCommandBuilder(profile.type, logger, profile);
const validateCommandAction = new ProfilesValidateCommandBuilder(profile.type, logger, profile);
const listCommandAction = new ProfilesListCommandBuilder(profile.type, logger, profile);
const setCommandAction = new ProfilesSetCommandBuilder(profile.type, logger, profile);
updateGroup.children.push(updateCommandAction.build());
deleteGroup.children.push(deleteCommandAction.build());
// validate profile is optional depending on if the profile has a validation plan
const validateCommandResult = validateCommandAction.build();
if (!isNullOrUndefined(validateCommandResult)) {
validateGroup.children.push(validateCommandResult);
}
listGroup.children.push(listCommandAction.build());
createGroup.children.push(createCommandAction.build());
setGroup.children.push(setCommandAction.build());
}
profileGroup.children.push(createGroup, updateGroup, deleteGroup, listGroup, setGroup);
if (validateGroup.children.length > 0) {
// don't bother to add validation commands unless some plans have been providedl
profileGroup.children.push(validateGroup);
}
return profileGroup;
}
}