Skip to content

Commit

Permalink
cli: don't error if the user folder doesn't exist (#4508)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brunnre8 committed Apr 12, 2022
1 parent 37d7de7 commit 8153198
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/clientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
20 changes: 7 additions & 13 deletions src/command-line/users/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
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
.command("list")
.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();

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

0 comments on commit 8153198

Please sign in to comment.