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
/
ListProfilesHandler.ts
69 lines (58 loc) · 2.38 KB
/
ListProfilesHandler.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
/*
* 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 { Imperative } from "../../../";
import { ProfilesConstants } from "../../../../profiles/src/constants/ProfilesConstants";
import { CliProfileManager, ICommandHandler, IHandlerParameters } from "../../../../cmd";
import { IProfileLoaded } from "../../../..";
/**
* Handler for the auto-generated list profiles command.
*/
export default class ListProfilesHandler implements ICommandHandler {
/**
* The process command handler for the "list profiles" command.
* @return {Promise<ICommandResponse>}: The promise to fulfill when complete.
*/
public async process(params: IHandlerParameters): Promise<void> {
// Extract the profile type, profile manager, and the default profile
const profileType: string = params.definition.customize[ProfilesConstants.PROFILES_COMMAND_TYPE_KEY];
const profileManager: CliProfileManager = Imperative.api.profileManager(profileType);
const defaultName = profileManager.getDefaultProfileName();
// Load all profiles for the type contained in the manager
const loadResults: IProfileLoaded[] = await profileManager.loadAll({noSecure: true, typeOnly: true});
// Set the data object
params.response.data.setMessage(`"${loadResults.length}" profiles loaded for type "${profileType}"`);
params.response.data.setObj(loadResults);
// Construct the format print list
const print = [];
for (const result of loadResults) {
if (result.name === defaultName) {
result.name += " (default) ";
}
print.push({
name: result.name,
contents: result.profile
});
}
// Format the results accord to the contents
if (params.arguments.showContents) {
params.response.format.output({
output: print,
format: "object"
});
} else {
params.response.format.output({
output: print,
fields: ["name"],
format: "list"
});
}
}
}