hardlounge/server/command-line/users/remove.ts

35 lines
925 B
TypeScript
Raw Permalink Normal View History

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
const program = new Command("remove");
2014-09-13 21:29:45 +00:00
program
.description("Remove an existing user")
.on("--help", Utils.extraHelp)
.argument("<name>", "name of the user")
.action(function (name) {
if (!fs.existsSync(Config.getUsersPath())) {
log.error(`${Config.getUsersPath()} does not exist.`);
return;
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ClientManager = require("../../clientManager").default;
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.`);
}
} catch (e: any) {
// There was an error, already logged
2014-09-13 21:29:45 +00:00
}
});
export default program;