feat(cli): add delete command

This commit is contained in:
ty
2026-03-22 14:47:47 +08:00
parent 7f45884141
commit 730cfe9eb7
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import { Command } from "commander";
import { api } from "../api.js";
import { log, printJson, printText } from "../output.js";
export function registerDeleteCommand(program: Command) {
program
.command("delete")
.description("Delete a mailbox or message")
.requiredOption("--email-id <id>", "email ID")
.option("--message-id <id>", "message ID (omit to delete entire mailbox)")
.action(async (opts) => {
const json = program.opts().json;
try {
if (opts.messageId) {
await api.deleteMessage(opts.emailId, opts.messageId);
if (json) {
printJson({ success: true });
} else {
printText(`Deleted message ${opts.messageId}`);
}
} else {
await api.deleteEmail(opts.emailId);
if (json) {
printJson({ success: true });
} else {
printText(`Deleted mailbox ${opts.emailId}`);
}
}
} catch (e: any) {
log(`Error: ${e.message}`);
process.exit(1);
}
});
}

View File

@@ -5,6 +5,7 @@ import { registerCreateCommand } from "./commands/create.js";
import { registerListCommand } from "./commands/list.js";
import { registerWaitCommand } from "./commands/wait.js";
import { registerReadCommand } from "./commands/read.js";
import { registerDeleteCommand } from "./commands/delete.js";
const program = new Command();
@@ -19,5 +20,6 @@ registerCreateCommand(program);
registerListCommand(program);
registerWaitCommand(program);
registerReadCommand(program);
registerDeleteCommand(program);
program.parse();