hardlounge/src/command-line/list.js

40 lines
960 B
JavaScript
Raw Normal View History

"use strict";
const colors = require("colors/safe");
const program = require("commander");
const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils");
2014-09-13 21:29:45 +00:00
program
.command("list")
2014-10-03 23:33:44 +00:00
.description("List all users")
.on("--help", Utils.extraHelp)
2014-09-13 21:29:45 +00:00
.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.`);
}
2014-09-13 21:29:45 +00:00
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("lounge add <name>")}.`);
2014-09-13 21:29:45 +00:00
}
});