Add command modules and tests; commit remaining changes

This commit is contained in:
Peter Steinberger
2025-11-25 00:12:12 +01:00
parent 52e0c8de25
commit 938e237411
31 changed files with 11269 additions and 7 deletions

30
src/commands/status.ts Normal file
View File

@@ -0,0 +1,30 @@
import type { CliDeps, RuntimeEnv } from "../index.js";
import { formatMessageLine } from "../index.js";
export async function statusCommand(
opts: { limit: string; lookback: string; json?: boolean },
deps: CliDeps,
runtime: RuntimeEnv,
) {
const limit = Number.parseInt(opts.limit, 10);
const lookbackMinutes = Number.parseInt(opts.lookback, 10);
if (Number.isNaN(limit) || limit <= 0 || limit > 200) {
throw new Error("limit must be between 1 and 200");
}
if (Number.isNaN(lookbackMinutes) || lookbackMinutes <= 0) {
throw new Error("lookback must be > 0 minutes");
}
const messages = await deps.listRecentMessages(lookbackMinutes, limit);
if (opts.json) {
runtime.log(JSON.stringify(messages, null, 2));
return;
}
if (messages.length === 0) {
runtime.log("No messages found in the requested window.");
return;
}
for (const m of messages) {
runtime.log(formatMessageLine(m));
}
}