mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 12:03:11 +00:00
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
2 changed files with 11 additions and 13 deletions
|
@ -145,6 +145,10 @@ ClientManager.prototype.loadUser = function (name) {
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientManager.prototype.getUsers = function () {
|
ClientManager.prototype.getUsers = function () {
|
||||||
|
if (!fs.existsSync(Helper.getUsersPath())) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return fs
|
return fs
|
||||||
.readdirSync(Helper.getUsersPath())
|
.readdirSync(Helper.getUsersPath())
|
||||||
.filter((file) => file.endsWith(".json"))
|
.filter((file) => file.endsWith(".json"))
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
const log = require("../../log");
|
const log = require("../../log");
|
||||||
const colors = require("chalk");
|
const colors = require("chalk");
|
||||||
const program = require("commander");
|
const program = require("commander");
|
||||||
const fs = require("fs");
|
|
||||||
const Helper = require("../../helper");
|
|
||||||
const Utils = require("../utils");
|
const Utils = require("../utils");
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -12,11 +10,6 @@ program
|
||||||
.description("List all users")
|
.description("List all users")
|
||||||
.on("--help", Utils.extraHelp)
|
.on("--help", Utils.extraHelp)
|
||||||
.action(function () {
|
.action(function () {
|
||||||
if (!fs.existsSync(Helper.getUsersPath())) {
|
|
||||||
log.error(`${Helper.getUsersPath()} does not exist.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ClientManager = require("../../clientManager");
|
const ClientManager = require("../../clientManager");
|
||||||
const users = new ClientManager().getUsers();
|
const users = new ClientManager().getUsers();
|
||||||
|
|
||||||
|
@ -25,16 +18,17 @@ program
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (users.length > 0) {
|
if (users.length === 0) {
|
||||||
log.info("Users:");
|
|
||||||
users.forEach((user, i) => {
|
|
||||||
log.info(`${i + 1}. ${colors.bold(user)}`);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
log.info(
|
log.info(
|
||||||
`There are currently no users. Create one with ${colors.bold(
|
`There are currently no users. Create one with ${colors.bold(
|
||||||
"thelounge add <name>"
|
"thelounge add <name>"
|
||||||
)}.`
|
)}.`
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("Users:");
|
||||||
|
users.forEach((user, i) => {
|
||||||
|
log.info(`${i + 1}. ${colors.bold(user)}`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue