diff --git a/server/commands/user.ts b/server/commands/user.ts index b17b93b..224e90f 100644 --- a/server/commands/user.ts +++ b/server/commands/user.ts @@ -12,7 +12,7 @@ type UserFlags = (typeof UserCommand)["flags"] extends Input ? F : never; -type Action = "create" | "update" | "delete"; +type Action = "show" | "create" | "update" | "delete"; // tslint:disable:no-shadowed-variable @@ -20,6 +20,11 @@ export default class UserCommand extends ManageCommand { static description = "Manage users"; static flags = { + show: flags.boolean({ + char: "s", + exclusive: ["create", "update", "delete"], + description: "Show user(s)", + }), create: flags.boolean({ char: "c", exclusive: ["update", "delete", "id"], @@ -53,11 +58,12 @@ export default class UserCommand extends ManageCommand { }; getAction(flags: UserFlags): Action { - if (flags.create) return "create"; + if (flags.show) return "show"; + else if (flags.create) return "create"; else if (flags.update) return "update"; else if (flags.delete) return "delete"; else { - this.error("Must specify an action (--create, --update, --delete)", { + this.error("Must specify an action (--show, --create, --update, --delete)", { exit: false }); return this._help(); @@ -105,6 +111,26 @@ export default class UserCommand extends ManageCommand { await this.connect(); + if (flags.show) { + let whereClause: FindConditions = {}; + if (flags.id) { + whereClause.id = flags.id; + } + if (flags.username) { + whereClause.username = flags.username; + } + const users = await this.database.users.find({ where: whereClause }); + if (users.length == 0) { + console.log("No users found"); + return 1; + } + console.log("Users: ") + for (const user of users) { + console.log(JSON.stringify(user.toJSON())); + } + return; + } + const user = await this.getOrDeleteUser(flags, action); if (flags.username && (flags.create || flags.id)) {