mirror of
https://github.com/beilunyang/moemail.git
synced 2026-09-04 23:06:37 +08:00
feat(cli): add delete command
This commit is contained in:
@@ -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 { registerListCommand } from "./commands/list.js";
|
||||||
import { registerWaitCommand } from "./commands/wait.js";
|
import { registerWaitCommand } from "./commands/wait.js";
|
||||||
import { registerReadCommand } from "./commands/read.js";
|
import { registerReadCommand } from "./commands/read.js";
|
||||||
|
import { registerDeleteCommand } from "./commands/delete.js";
|
||||||
|
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
|
|
||||||
@@ -19,5 +20,6 @@ registerCreateCommand(program);
|
|||||||
registerListCommand(program);
|
registerListCommand(program);
|
||||||
registerWaitCommand(program);
|
registerWaitCommand(program);
|
||||||
registerReadCommand(program);
|
registerReadCommand(program);
|
||||||
|
registerDeleteCommand(program);
|
||||||
|
|
||||||
program.parse();
|
program.parse();
|
||||||
|
|||||||
Reference in New Issue
Block a user