Browse Source

Add user --show command

develop
Alex Mikhalev 6 years ago
parent
commit
e391c26b95
  1. 32
      server/commands/user.ts

32
server/commands/user.ts

@ -12,7 +12,7 @@ type UserFlags = (typeof UserCommand)["flags"] extends Input<infer F>
? F ? F
: never; : never;
type Action = "create" | "update" | "delete"; type Action = "show" | "create" | "update" | "delete";
// tslint:disable:no-shadowed-variable // tslint:disable:no-shadowed-variable
@ -20,6 +20,11 @@ export default class UserCommand extends ManageCommand {
static description = "Manage users"; static description = "Manage users";
static flags = { static flags = {
show: flags.boolean({
char: "s",
exclusive: ["create", "update", "delete"],
description: "Show user(s)",
}),
create: flags.boolean({ create: flags.boolean({
char: "c", char: "c",
exclusive: ["update", "delete", "id"], exclusive: ["update", "delete", "id"],
@ -53,11 +58,12 @@ export default class UserCommand extends ManageCommand {
}; };
getAction(flags: UserFlags): Action { 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.update) return "update";
else if (flags.delete) return "delete"; else if (flags.delete) return "delete";
else { else {
this.error("Must specify an action (--create, --update, --delete)", { this.error("Must specify an action (--show, --create, --update, --delete)", {
exit: false exit: false
}); });
return this._help(); return this._help();
@ -105,6 +111,26 @@ export default class UserCommand extends ManageCommand {
await this.connect(); await this.connect();
if (flags.show) {
let whereClause: FindConditions<User> = {};
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); const user = await this.getOrDeleteUser(flags, action);
if (flags.username && (flags.create || flags.id)) { if (flags.username && (flags.create || flags.id)) {

Loading…
Cancel
Save