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:
Reto 2022-04-12 02:46:29 +02:00 committed by GitHub
parent 37d7de7671
commit 815319810c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View File

@ -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"))

View File

@ -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)}`);
});
});