abuse-plus
Version:
A terminal which roasts you
38 lines (30 loc) โข 935 B
JavaScript
import { Command } from "commander";
import { LogManager } from "../core/logManager.js";
export const logsCommand = new Command("logs")
.description("๐ชต View or clear abuse CLI logs.")
.argument("[count]", "Number of recent logs to show", null)
.option("--clear", "Clear all logs")
.action((count, options) => {
if (options.clear) {
LogManager.clear();
console.log("๐งน Logs cleared!");
return;
}
const logs = LogManager.readLogs();
if (!logs.length) {
console.log("๐ญ No logs found.");
return;
}
let selectedLogs = logs;
if (count !== null) {
const n = parseInt(count, 10);
if (!isNaN(n) && n > 0) {
selectedLogs = logs.slice(-n);
}
}
console.log(`๐ Showing ${selectedLogs.length} log(s):\n`);
for (const log of selectedLogs) {
console.log(LogManager.format(log));
console.log(); // spacing
}
});