2025-12-10 21:26:02 +01:00
|
|
|
import { defineCommand } from "@clerc/core";
|
2025-02-26 00:00:21 +01:00
|
|
|
import confirm from "@inquirer/confirm";
|
|
|
|
|
import chalk from "chalk";
|
|
|
|
|
import { retrieveUser } from "../utils.ts";
|
|
|
|
|
|
2025-12-10 21:26:02 +01:00
|
|
|
export const deleteUserCommand = defineCommand({
|
|
|
|
|
name: "user delete",
|
|
|
|
|
alias: "user rm",
|
|
|
|
|
description: "Delete a user from the database. Can use username or handle.",
|
|
|
|
|
parameters: ["<username_or_handle>"],
|
|
|
|
|
flags: {
|
|
|
|
|
confirm: {
|
|
|
|
|
description: "Ask for confirmation before deleting the user",
|
|
|
|
|
type: Boolean,
|
|
|
|
|
alias: "c",
|
|
|
|
|
default: true,
|
2025-02-26 00:00:21 +01:00
|
|
|
},
|
|
|
|
|
},
|
2025-12-10 21:26:02 +01:00
|
|
|
handler: async (context) => {
|
2025-02-26 00:00:21 +01:00
|
|
|
const { confirm: confirmFlag } = context.flags;
|
2025-12-10 21:26:02 +01:00
|
|
|
const { username_or_handle } = context.parameters;
|
2025-02-26 00:00:21 +01:00
|
|
|
|
2025-12-10 21:26:02 +01:00
|
|
|
const user = await retrieveUser(username_or_handle);
|
2025-02-26 00:00:21 +01:00
|
|
|
|
|
|
|
|
if (!user) {
|
2025-12-10 21:26:02 +01:00
|
|
|
throw new Error(
|
|
|
|
|
`User ${chalk.gray(username_or_handle)} not found.`,
|
|
|
|
|
);
|
2025-02-26 00:00:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.info(`About to delete user ${chalk.gray(user.data.username)}!`);
|
|
|
|
|
console.info(`Username: ${chalk.blue(user.data.username)}`);
|
|
|
|
|
console.info(`Display Name: ${chalk.blue(user.data.displayName)}`);
|
2025-12-11 04:03:57 +01:00
|
|
|
console.info(
|
|
|
|
|
`Created At: ${chalk.blue(user.data.createdAt.toISOString())}`,
|
|
|
|
|
);
|
2025-02-26 00:00:21 +01:00
|
|
|
console.info(
|
|
|
|
|
`Instance: ${chalk.blue(user.data.instance?.baseUrl || "Local")}`,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (confirmFlag) {
|
|
|
|
|
const choice = await confirm({
|
|
|
|
|
message: `Are you sure you want to delete this user? ${chalk.red(
|
|
|
|
|
"This is irreversible.",
|
|
|
|
|
)}`,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!choice) {
|
|
|
|
|
throw new Error("Operation aborted.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await user.delete();
|
|
|
|
|
|
|
|
|
|
console.info(
|
|
|
|
|
`User ${chalk.gray(user.data.username)} has been deleted.`,
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-12-10 21:26:02 +01:00
|
|
|
});
|