2022-06-19 00:25:21 +00:00
|
|
|
import log from "../../log";
|
|
|
|
import colors from "chalk";
|
|
|
|
import {Command} from "commander";
|
|
|
|
import fs from "fs";
|
|
|
|
import Config from "../../config";
|
|
|
|
import Utils from "../utils";
|
2014-09-13 21:29:45 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const program = new Command("remove");
|
2014-09-13 21:29:45 +00:00
|
|
|
program
|
|
|
|
.description("Remove an existing user")
|
2017-08-21 05:49:32 +00:00
|
|
|
.on("--help", Utils.extraHelp)
|
2022-06-19 00:25:21 +00:00
|
|
|
.argument("<name>", "name of the user")
|
2020-03-21 20:55:36 +00:00
|
|
|
.action(function (name) {
|
2022-05-01 19:12:39 +00:00
|
|
|
if (!fs.existsSync(Config.getUsersPath())) {
|
|
|
|
log.error(`${Config.getUsersPath()} does not exist.`);
|
2017-07-18 09:36:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2017-12-07 02:23:46 +00:00
|
|
|
const ClientManager = require("../../clientManager");
|
2017-08-23 05:42:59 +00:00
|
|
|
const manager = new ClientManager();
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (manager.removeUser(name)) {
|
|
|
|
log.info(`User ${colors.bold(name)} removed.`);
|
|
|
|
} else {
|
|
|
|
log.error(`User ${colors.bold(name)} does not exist.`);
|
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
} catch (e: any) {
|
2017-08-23 05:42:59 +00:00
|
|
|
// There was an error, already logged
|
2014-09-13 21:29:45 +00:00
|
|
|
}
|
|
|
|
});
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
export default program;
|