Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: don't error if the user folder doesn't exist #4508

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of return early, keep the happy path to the left.
If you disagree heavily please tell me and I'll adapt my style.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either way is fine. Code style seems like a fairly low stakes thing in an OSS code case with an auto formatter too.

}

log.info("Users:");
users.forEach((user, i) => {
log.info(`${i + 1}. ${colors.bold(user)}`);
});
});