cli: don't error if the user folder doesn't exist (#4508)
The user folder gets created on demand, thelounge list should not fail if the folder doesn't exist. This just means that no users are present, so report that instead.
This commit is contained in:
parent
37d7de7671
commit
815319810c
@ -145,6 +145,10 @@ ClientManager.prototype.loadUser = function (name) {
|
||||
};
|
||||
|
||||
ClientManager.prototype.getUsers = function () {
|
||||
if (!fs.existsSync(Helper.getUsersPath())) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return fs
|
||||
.readdirSync(Helper.getUsersPath())
|
||||
.filter((file) => file.endsWith(".json"))
|
||||
|
@ -3,8 +3,6 @@
|
||||
const log = require("../../log");
|
||||
const colors = require("chalk");
|
||||
const program = require("commander");
|
||||
const fs = require("fs");
|
||||
const Helper = require("../../helper");
|
||||
const Utils = require("../utils");
|
||||
|
||||
program
|
||||
@ -12,11 +10,6 @@ program
|
||||
.description("List all users")
|
||||
.on("--help", Utils.extraHelp)
|
||||
.action(function () {
|
||||
if (!fs.existsSync(Helper.getUsersPath())) {
|
||||
log.error(`${Helper.getUsersPath()} does not exist.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const ClientManager = require("../../clientManager");
|
||||
const users = new ClientManager().getUsers();
|
||||
|
||||
@ -25,16 +18,17 @@ program
|
||||
return;
|
||||
}
|
||||
|
||||
if (users.length > 0) {
|
||||
log.info("Users:");
|
||||
users.forEach((user, i) => {
|
||||
log.info(`${i + 1}. ${colors.bold(user)}`);
|
||||
});
|
||||
} else {
|
||||
if (users.length === 0) {
|
||||
log.info(
|
||||
`There are currently no users. Create one with ${colors.bold(
|
||||
"thelounge add <name>"
|
||||
)}.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("Users:");
|
||||
users.forEach((user, i) => {
|
||||
log.info(`${i + 1}. ${colors.bold(user)}`);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user