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
/
ImperativeApi.ts
81 lines (72 loc) · 2.54 KB
/
ImperativeApi.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
/*
* 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 { IImperativeConfig } from "../doc/IImperativeConfig";
import { IImperativeApi } from "./doc/IImperativeApi";
import { Logger } from "../../../logger";
import { ProfileUtils } from "../../../profiles";
import { CliProfileManager } from "../../../cmd";
export class ImperativeApi {
/**
* index signature for accessing Imperative api via dictionary [] notation.
*/
[key: string]: any
/**
* Input parameters to construct the API object
*/
private mLog: Logger;
private mCustomLoggerMap: { [key: string]: Logger } = {};
constructor(private mApis: IImperativeApi, private mConfig: IImperativeConfig, private mHome: string) {
}
/**
* Returns the imperative logger API object
* @returns {Logger}: The imperative logger api object.
*/
public get imperativeLogger(): Logger {
return this.mApis.imperativeLogger;
}
/**
* Returns an imperative app's logger API object
* @returns {Logger}: The imperative app's logger api object.
*/
public get appLogger(): Logger {
return this.mApis.appLogger;
}
/**
* Retrieve a named custom logger that has been configured
* @param {string} name - the name of the custom logger
* @returns {Logger} the configured logger, if it exists
*/
public additionalLogger(name: string): Logger {
return this.mCustomLoggerMap[name];
}
/**
* Register a logger with the Imperative API
* Mostly used internally in Imperative
* @param {string} name - the name of the logger to register
* @param {Logger} logger - the logger to store
*/
public addAdditionalLogger(name: string, logger: Logger): void {
this.mCustomLoggerMap[name] = logger;
}
/**
* Return an instance of a profile manager for a given profile type
* See ProfileManager.ts for more details
*/
public profileManager(type: string): CliProfileManager {
return new CliProfileManager({
type,
typeConfigurations: this.mConfig.profiles,
profileRootDirectory: ProfileUtils.constructProfilesRootDirectory(this.mHome),
logger: this.imperativeLogger,
productDisplayName: this.mConfig.productDisplayName
});
}
}