thelounge/src/command-line/list.js
Jérémie Astori aca23257ed
Switch CLI tool from lounge to thelounge and deprecate lounge
This is in preparation of The Lounge v3 which will make `thelounge` uniform across the entire project. No more confusion!
2017-11-22 16:37:26 -05:00

40 lines
963 B
JavaScript

"use strict";
const colors = require("colors/safe");
const program = require("commander");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
program
.command("list")
.description("List all users")
.on("--help", Utils.extraHelp)
.action(function() {
if (!fs.existsSync(Helper.USERS_PATH)) {
log.error(`${Helper.USERS_PATH} does not exist.`);
return;
}
const ClientManager = require("../clientManager");
if (Helper.config.public) {
log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
}
var users = new ClientManager().getUsers();
if (users === undefined) { // There was an error, already logged
return;
}
if (users.length > 0) {
log.info("Users:");
users.forEach((user, i) => {
log.info(`${i + 1}. ${colors.bold(user)}`);
});
} else {
log.info(`There are currently no users. Create one with ${colors.bold("thelounge add <name>")}.`);
}
});