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
/
uninstall.handler.ts
66 lines (62 loc) · 2 KB
/
uninstall.handler.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
/*
* 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 { ICommandHandler, ICommandResponse, IHandlerParameters } from "../../../../../cmd";
import { Logger } from "../../../../../logger/";
import { PMFConstants } from "../../utilities/PMFConstants";
import { uninstall } from "../../utilities/npm-interface";
import { ImperativeError } from "../../../../../error";
import { TextUtils } from "../../../../../utilities";
/**
* The uninstall command handler for cli plugin install.
*
* @see {uninstallDefinition}
*/
export default class UninstallHandler implements ICommandHandler {
/**
* A logger for this class
*
* @private
* @type {Logger}
*/
private console: Logger = Logger.getImperativeLogger();
/**
* Process the command and input.
*
* @param {IHandlerParameters} params Parameters supplied by yargs
*
* @param {string[]} [params.arguments.plugin] This is the plugin to uninstall.
*
* @returns {Promise<ICommandResponse>} The command response
*
* @throws {ImperativeError}
*/
public async process(params: IHandlerParameters): Promise<void> {
const chalk = TextUtils.chalk;
this.console.debug(`Root Directory: ${PMFConstants.instance.PLUGIN_INSTALL_LOCATION}`);
if (params.arguments.plugin == null || params.arguments.plugin.length === 0) {
throw new ImperativeError({
msg: `${chalk.yellow.bold("Package name")} is required.`
});
} else {
try {
uninstall(params.arguments.plugin);
params.response.console.log("Removal of the npm package(s) was successful.\n"
);
} catch (e) {
throw new ImperativeError({
msg: "Uninstall Failed",
causeErrors: [e],
additionalDetails: e.message
});
}
}
}
}