mirror of
https://github.com/beilunyang/moemail.git
synced 2026-05-10 17:43:06 +08:00
feat(cli): add delete command
This commit is contained in:
34
packages/cli/src/commands/delete.ts
Normal file
34
packages/cli/src/commands/delete.ts
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user