feat(cli): add send command

This commit is contained in:
ty
2026-03-22 14:48:58 +08:00
committed by BeilunYang
parent f29565c90d
commit b09cc28496
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { Command } from "commander";
import { api } from "../api.js";
import { log, printJson, printText } from "../output.js";
export function registerSendCommand(program: Command) {
program
.command("send")
.description("Send an email from a temporary address")
.requiredOption("--email-id <id>", "email ID to send from")
.requiredOption("--to <address>", "recipient email address")
.requiredOption("--subject <subject>", "email subject")
.requiredOption("--content <content>", "email body text")
.action(async (opts) => {
const json = program.opts().json;
try {
const result = (await api.sendEmail(opts.emailId, {
to: opts.to,
subject: opts.subject,
content: opts.content,
})) as any;
if (json) {
printJson({
success: true,
remainingEmails: result.remainingEmails,
});
} else {
printText(`Email sent successfully. Remaining today: ${result.remainingEmails}`);
}
} catch (e: any) {
log(`Error: ${e.message}`);
process.exit(1);
}
});
}

View File

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